To begin, I'd like to explain that the following class works in tandem with a process that detects incoming email messages to a case and then sends the ID of that email message to the class.
The class should then get the Email Ids and send out an email to every follower of that case.
This class and process are working together beautifully in our sandbox environment, but something is going very awry in our production environment, as we haven't received any emails to our test follower accounts.
Can anyone spot something(s) that might cause this discrepancy, or should I dive further into Salesforce configurations to find the answer?
global class CaseEmailFollowersNotify { @InvocableMethod(label='Case Email to Followers Notify' description='emails followers of new case email') global static void GetCaseCommentIds(List<Id> EmailIds) { for(emailmessage em : [SELECT Id, ParentId, FromAddress, TextBody FROM EmailMessage WHERE Id in: EmailIds]) { string tbody = em.TextBody; string tbody2 = tbody; if(tbody.length() > 60) { tbody2 = tbody.substring(0, 59); } tbody2 = tbody2 + '...'; List<EntitySubscription> e = [select Id, ParentId, SubscriberId from EntitySubscription where ParentId =: em.ParentId]; for(EntitySubscription es : e) { List<User> u = [select Email, Id from User where Id =: es.SubscriberId]; Case ca = [select Subject, CaseNumber from Case where Id =: es.ParentId limit 1]; for(User us : u) { Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); mail.setHTMLBody('blahbalhblah'); mail.setTargetObjectId(us.Id); mail.setWhatId(es.ParentId); mail.setSubject('Case Following New Email'); mail.setSenderDisplayName('Case Following Update'); mail.saveAsActivity = false; Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail }); } } } } } Any help is sorely appreciated! Please note that the string manipulation is entirely to do with our email formatting and only exists to edit down the incoming email's contents to something that can be sent back out and abbreviated.