+ Start a Discussion

Trigger and email

Hello Gurus, There is a requirement to have a trigger to fire an email on certain critera on an opportuntiy - which is okay. My questions is how do i link or store those outbound emails and any response to that email to that opportunity with its contents? Can anyone direct me to an example? Thanks for the help in advance!

Santosh KumbarSantosh Kumbar

Use Below Example in Trigger..... GIve Email Template ID(I highlighted that section).


 Id TemplateId = [Select e.Name, e.Id From EmailTemplate e WHERE e.Name =:'BusineesCall'].Id;

 Messaging.MassEmailMessage SurveyMail = new Messaging.MassEmailMessage();    



contactfield = [Select c.Id, c.email From Contact c WHERE c.Id IN : lstRecords ];    


for(contact contactobj1 : contactfield ){                 






Messaging.sendEmail(new Messaging.Email[] {SurveyMail});      


Thanks for the example. Lets say trigger sends the email: What i need is 1) I want to store the email as task (with email content) sent under opportunity 2) Let's say somebody replies to that email: I want that inbound email to be stored as task (with email content). How can I acheive this?