October 17, 2020

How to clone EmailMessage record using Apex in Salefsorce?

Sample code:

EmailMessage objEM = [ SELECT BccAddress, BccIds, CcAddress, CcIds,
                              ContentDocumentIds,  
                                EmailTemplateId, FirstOpenedDate, FromAddress, FromName,
                                  HasAttachment, Headers, HtmlBody, Incoming, IsBounced,
                                  IsClientManaged, IsDeleted, IsExternallyVisible, IsOpened,
                                  IsTracked, LastOpenedDate, MessageDate,
                                  MessageIdentifier, ParentId, RelatedToId, ReplyToEmailMessageId,
                                  Status, Subject, TextBody, ThreadIdentifier, ToAddress,  
                                  ValidatedFromAddress
                         FROM EmailMessage WHERE Id = '<Id of the Record>' ];

EmailMessage objCloneEM = objEM.clone();
objCloneEM.HTMLBody = 'Testing';//Updating Body
objCloneEM.TextBody = 'Testing';//Updating Body
insert objCloneEM;

No comments:

Post a Comment