1

I have a custom object 'XYZ' on which I have a button "Send Email", When user click on this button a email will be sent to the email address mentioned on the record of XYZ. Now my requirement is to track history of email, when some one sends a email, Activity history should be updated as we see with salesforce standard functionality. Can any one please suggest me how this functionality can be achieved? Please comment the code that will be very helpful.

Thanks.

3 Answers 3

1

In Apex Code or using the SOAP API, sendEmail accepts a list of messages to send. To save the email as a new task to the associated record, use the setSaveAsActivity flag to true on the message. This flag must be "false" when sending emails to users.

-1

Enable enhance email from set up and then write a trigger on EmailMessage object to insert a record with whoId or whatId based on your requirement.

Thanks, Avijit

-3

Try sending the email through email author. It automatically saves the sent email as a Task in Activity history. Plus, you have the liberty to use email templates also. You just need to modify the logic you are using in your Send Email custom button. Here is the post I wrote explaining its functionality. Please refer the same to achieve your requirement.

How to send email from email author

Hope that works.

4
  • 1
    You can't use EmailAuthor in Apex Code at all. They've actually disabled this ability in order to prevent people bypassing the mass mail limits.
    – sfdcfox
    Commented Jun 7, 2015 at 20:29
  • @sfdcfox The question is not clear. Don't know if he is using custom button to call apex or simply using javascript. Hence, suggested email author as of now. Commented Jun 7, 2015 at 20:32
  • It's tagged apex, and if they were using EmailAuthor, it would save the email as a task automatically.
    – sfdcfox
    Commented Jun 7, 2015 at 20:36
  • Yes right. I was about to suggest him through apex after his response. The only thing to make this work would be to use a template because setTargetObjectId(Id) is required when using a template AND setSaveAsActivity won't work until receivers are based on targetObjectId. Commented Jun 7, 2015 at 20:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .