You need to sign in to do that
Don't have an account?
wrtie trigger with helper c;ass to send email when new conatc is inserted when email filled
I have Write a trigger on Contact , when a contact insert an email should be sent to contact email id with specified template. I have written the code & it doesm't give any error but i am not getting my result... i want to wrtie with helper class... it woked fine for me with direct trigger...
****APEX TRIGGER*****
PLZ HELP ME WITH THIS CODE
****APEX TRIGGER*****
trigger helperSendEmailTOCon on Contact (after Insert, after Update) { helperClassSendEmailToCon obj = new helperClassSendEmailToCon(); if(trigger.isInsert && trigger.isAfter) { obj.onAfterInsert(trigger.new); } }****APEX CLASS****
public class helperClassSendEmailToCon { public void onAfterInsert(List<Contact> triggerNew) { InsertEmailOnContact(triggerNew); } void InsertEmailOnContact(List<Contact> triggerNew) { EmailTemplate et = [select id from EmailTemplate where name =:'InsertContact']; List<Messaging.SingleEmailMessage> emails = new List<Messaging.SingleEmailMessage>(); for(Contact con : triggerNew) { if(con.email!=null) { Messaging.singleEmailMessage singleEmail = new Messaging.singleEmailMessage(); List<String> sendTo = new List<String>(); singleEMail.setCcAddresses(sendTo); singleEMail.setTargetObjectId(con.Id); singleEmail.setTemplateId(et.Id); singleEmail.setSaveAsActivity(false); emails.add(singleEmail ); } } messaging.sendEmail(emails); } }
PLZ HELP ME WITH THIS CODE
in apex class at line 11 just i have to remove :
EmailTemplate et = [select id from EmailTemplate where name = 'InsertContact'];