You need to sign in to do that
Don't have an account?
Sem Ingraf
Rif. Preventivo {{{Quote.Name}}} ({{{Quote.IdPreventivo__c}}})
Stato: {{{Quote.TranslatedStatus__c}}}
Mittente: {{{Sender.Name}}}
how could I do? is it possible to do this? I initially did a test with replace and replaceAll but without success.
Thanks for any help
EmailMessage modify TextBody and HtmlBody
Hi,
i have a trigger on the emailMessage object. I have a removeReplyText method that searches for some strings inside the TextBody and Htmlbody of the emailMessage object and deletes/hides it in order to streamline the display of the email when it is copied/stored on a case
private static void removeReplyText(List<EmailMessage> newObjects){ Map<Id, Case> casesMap; Set<Id> caseIds = new Set<Id>(); List<EmailMessage> emsToUpdate = new List<EmailMessage>(); for(EmailMessage em : newObjects){ System.debug('Clean body: ' + em.Id + ' - Parent: ' + em.ParentId); System.debug('Clean TXT: ' + em.TextBody); System.debug('Clean HTML: ' + em.HtmlBody); if(em.ParentId != null){ caseIds.add(em.ParentId); } } casesMap = new Map<Id, Case>(getCases(caseIds)); System.debug('CaseMap' +casesMap); for(EmailMessage em: newObjects){ Case myCase = casesMap.get(em.ParentId); Boolean changed = false; if(myCase != null){ System.debug('Found case'); String body = em.TextBody; if(String.isNotBlank(em.TextBody)) { Integer occurrence1 = body.indexOfIgnoreCase(Constants.EMAIL_QUOTEDBODY_1); Integer occurrence2 = body.indexOfIgnoreCase(Constants.EMAIL_QUOTEDBODY_2); Integer occurrence = occurrence1 != -1 && occurrence2 != -1 && occurrence1 < occurrence2 ? occurrence1 : occurrence2; //system.debug('occurrence3' +occurrence3); if (occurrence != -1) { body = body.substring(0, occurrence); // em.TextBody = body; changed = true; } system.debug('Constants.EMAIL_FooterPlain' +Constants.EMAIL_FooterPlain); Integer occurrenceFooter = body.indexOfIgnoreCase(Constants.EMAIL_FooterPlain); if (occurrenceFooter != -1) { body = body.substring(0, occurrenceFooter); // em.TextBody = body; changed = true; } } String htmlBody = em.HtmlBody; if(String.isNotBlank(em.HtmlBody)) { System.debug('HTML Body'); Integer occurrenceh1 = htmlBody.indexOfIgnoreCase(Constants.EMAIL_QUOTEDBODY_1); System.debug('occurrenceh1: ' + occurrenceh1); Integer occurrenceh2 = htmlBody.indexOfIgnoreCase(Constants.EMAIL_QUOTEDBODY_2); System.debug('occurrenceh2: ' + occurrenceh2); Integer occurrenceh = occurrenceh1 != -1 && occurrenceh2 != -1 && occurrenceh1 < occurrenceh2 ? occurrenceh1 : occurrenceh2; System.debug('occurrenceh: ' + occurrenceh); if (occurrenceh != -1) { htmlBody = htmlBody.substring(0, occurrenceh); htmlBody += '</body> </html>'; // em.HtmlBody = htmlBody; System.debug('new em.HtmlBody: ' + em.HtmlBody); changed = true; } system.debug('Constants.EMAIL_FooterHTML' +Constants.EMAIL_FooterHTML); Integer occurrenceFooter = htmlBody.indexOfIgnoreCase(Constants.EMAIL_FooterHTML); if (occurrenceFooter != -1) { htmlBody = htmlBody.substring(0, occurrenceFooter); // em.TextBody = body; changed = true; } } if (changed){ emsToUpdate.add(new EmailMessage(Id=em.Id, TextBody=body, HtmlBody=htmlBody)); } } } update emsToUpdate; }now I would like to modify this method to be able to delete/hide this initial piece as well :
Rif. Preventivo {{{Quote.Name}}} ({{{Quote.IdPreventivo__c}}})
Stato: {{{Quote.TranslatedStatus__c}}}
Mittente: {{{Sender.Name}}}
how could I do? is it possible to do this? I initially did a test with replace and replaceAll but without success.
Thanks for any help
Here is an example of how you could modify the method to remove the initial pattern:
If you find my answer helpful, please mark it as the best answer. Thanks!