Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.78 KB | None | 0 0
  1. public without sharing class TR001_EmailMessage {
  2.  
  3.     /**
  4.     * @description Process to detect if there is a spam from a custom, creating loads and loads of cases.
  5.     * @param emailsList List of email
  6.     */
  7.     public static void DetectCreationFromSpam (Map<ID, EmailMessage> emailsList) {
  8.         system.debug('### START TR002_EmailMessage : DetectCreationFromSpam');
  9.        
  10.         try {      
  11.             // Email Blacklist
  12.             List<EMAILBLACKLIST__c> emailsBlacklist = EMAILBLACKLIST__c.getAll().Values();
  13.            
  14.             if(!emailsList.isEmpty() ){
  15.                 // For all emails in list, compare Email address and Subject with the custom settings
  16.                 for (EmailMessage newEmail : emailsList.values()) {            
  17.                     system.debug('## Email FROM: ' + newEmail.FromAddress);
  18.                     system.debug('## Case ID: '+newEmail.ParentId);
  19.                     for(EMAILBLACKLIST__c emailBlacklist : emailsBlacklist) {
  20.                         if(emailBlacklist.Name.containsIgnoreCase(newEmail.FromAddress) && String.isBlank(newEmail.Subject)){
  21.                             newEmail.addError('## ERROR : Spam Email :\n '+newEmail);
  22.                         }
  23.                         if(emailBlacklist.Name.containsIgnoreCase(newEmail.FromAddress) && emailBlacklist.SUBJECT__c.containsIgnoreCase(newEmail.Subject)){
  24.                             newEmail.addError('## ERROR : Spam Email :\n '+newEmail);
  25.                         }
  26.                     }
  27.                 }
  28.             }
  29.             system.debug('### END TR002_EmailMessage : DetectCreationFromSpam');
  30.         }  catch (Exception e) {
  31.             system.debug('ERROR # Detect Email Spam (' + e + ') Line : ' + String.valueOf(e.getLineNumber()) + ' !');
  32.             throw e;
  33.         }
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement