function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ 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