Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public without sharing class TR001_EmailMessage {
- /**
- * @description Process to detect if there is a spam from a custom, creating loads and loads of cases.
- * @param emailsList List of email
- */
- public static void DetectCreationFromSpam (Map<ID, EmailMessage> emailsList) {
- system.debug('### START TR002_EmailMessage : DetectCreationFromSpam');
- try {
- // Email Blacklist
- List<EMAILBLACKLIST__c> emailsBlacklist = EMAILBLACKLIST__c.getAll().Values();
- if(!emailsList.isEmpty() ){
- // For all emails in list, compare Email address and Subject with the custom settings
- for (EmailMessage newEmail : emailsList.values()) {
- system.debug('## Email FROM: ' + newEmail.FromAddress);
- system.debug('## Case ID: '+newEmail.ParentId);
- for(EMAILBLACKLIST__c emailBlacklist : emailsBlacklist) {
- if(emailBlacklist.Name.containsIgnoreCase(newEmail.FromAddress) && String.isBlank(newEmail.Subject)){
- newEmail.addError('## ERROR : Spam Email :\n '+newEmail);
- }
- if(emailBlacklist.Name.containsIgnoreCase(newEmail.FromAddress) && emailBlacklist.SUBJECT__c.containsIgnoreCase(newEmail.Subject)){
- newEmail.addError('## ERROR : Spam Email :\n '+newEmail);
- }
- }
- }
- }
- system.debug('### END TR002_EmailMessage : DetectCreationFromSpam');
- } catch (Exception e) {
- system.debug('ERROR # Detect Email Spam (' + e + ') Line : ' + String.valueOf(e.getLineNumber()) + ' !');
- throw e;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement