Problem : How to show Email sent from Salesforce in activity history of an object
Solution : Here are the steps :
1. Set WhatId
2. Make SaveAsActivity true
Code Sample:
Messaging.SingleEmailMessage emailTobeSent = new Messaging.SingleEmailMessage(); ListToAddress = new List (); ToAddress.add(‘Example@gmail.com’); emailTobeSent.setToAddresses(ToAddress); emailTobeSent.setSubject('Subject); emailTobeSent.setHtmlBody('Please see the attachments'); emailTobeSent.setWhatid(RecordId);//Put the record id of record for which you want make activity history in place of RecordId. emailTobeSent.setSaveAsActivity(true); // Messaging.SendEmailResult [] r1 = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {emailTobeSent});
Webner Solutions is a Software Development company focused on developing CRM apps (Salesforce, Zoho), LMS Apps (Moodle/Totara), Websites and Mobile apps. If you need Salesforce customization, App development or any other software development assistance please contact us at salesforce@webners.com