+ Start a Discussion
sivadevsivadev 

Please help me on this i struck on this i have email templates

Please help me on this i struck on this i have email templates stored in folder when selecting email template the email should go to contact and Line manger of contact  to should be Line manger CC should be Contact name 

please help me on this 

Ajay_SFDCAjay_SFDC
Hi there ,

You can use the following way :

EmailTemplate template = [SELECT Id FROM EmailTemplate WHERE Name = 'Your Template' LIMIT 1];
 
Messaging.SingleEmailMessage msg = new Messaging.SingleEmailMessage();
msg.setTemplateId(template.Id);
msg.setTargetObjectId('Set Contact Id here'); // You can use Contact , Lead , User here
msg.setWhatId('Set What Id Here '); // If you use Contact then WhatId must be Account ,Asset,Campaign,Case,Contact
//msg.setToAddresses(toAddresses); // IF you are not using TargetObjectId,WhatID
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { msg });

Thanks ,
 Ajay