Scenario:
Want to see the sent emails in the message list in communication tab in the sales order (Transaction record)
Solution:
Add the parameter “options.relatedRecords” to the email.send(options), and give the transaction records id as value for this parameter for attaching the mail to transaction record
options.relatedRecords : Object that contains key/value pairs to associate (attach) the Message record with related records (that is, transaction, activity, entity, and custom records).
Sample code snippet:
email.send({
author: senderId,
recipients: recipientId,
subject: 'Test Sample Email Module',
body: 'email body',
attachments: [fileObj],
relatedRecords: {
entityId: recipientId,
customRecord:{
id:recordId,
recordType: recordTypeId //an integer value
}
}
});