function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
aditya prasadaditya prasad 

Is it possible to create a record under Emails related list in case record when send an email from vf page?

Is it possible to create record under Emails related list in a case record whenever send email from custom vf page using apex.User-added image
SYED MOOSA NAZIR T NSYED MOOSA NAZIR T N

Yes. We have provision to create a record Email Related List (EmailMessage object).
Note : Below code is a Sample code for your reference.

EmailMessage EmailMesssageRec = new EmailMessage (
        ParentId = CaseRecord.Id,
        FromName = 'FromName',
        FromAddress = 'FromEmailAddress@salesforce.com',
        ToAddress = 'ToEmailAddress@salesforce.com',
        Subject = 'EmailSubject',
        TextBody = 'TextBody',
        MessageDate = 'DateTimeFormat',
        Status = 'New',
        Incoming = true,
        Headers = 'Internet message headers of the incoming email',
        ActivityId = Activity.id        
    );
    insert EmailMesssageRec;

 

Kindly go through the below Salesforce documentation to understand the fields available in EmailMessage object.

https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_emailmessage.htm

 


Please let us know if this will help you
Thanks
Syed Moosa Nazir TN
smartmoosa@gmail.com