You need to sign in to do that
Don't have an account?

how to send email to Account Owner from contract object in Batch Class
Can any one help me out . How to send an email to Account Owner from contract object in Batch Class.Im using templateid ,in target object im giving the contact id ,in whatid im sending the Account owner email ,but the Account owner is not getting any email.What im doing is correct .Any help very much appreciated.
Portion of the Code :
Portion of the Code :
global void execute(Database.BatchableContext bc, List < Contract > recs) { List < Messaging.SingleEmailMessage > mailList = new List < Messaging.SingleEmailMessage > (); for (Contract c: recs) { if (c.Contact_Email__c != null) { List < String > toAddresses = new List < String > (); List < String > CcAddresses = new List < String > (); Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); //toAddresses.add(c.Contact_Email__c); ccAddresses.add(c.Account.Owner.Email); //toAddresses.add(c.Account.Owner.Manager.Email); // mail.setToAddresses(toAddresses); mail.setCcAddresses(CcAddresses); mail.setTargetObjectId('c.contact__r.Id)'); mail.setWhatId(c.Account.Owner.Manager.Email)); mail.setTemplateId('00X4B000000M3go'); mail.setSaveAsActivity(false); mailList.add(mail); } } Messaging.sendEmail(mailList); }
I have tested this code now by running in my dev org, this will be working for sure, few small mistakes that you need to modify
1. At line no. 14 it should be Id, not string.
2. Line 15 an extra ')'
Other things are fine, please make sure that you are querying the field in the start method those you are using in this method
Here is the code, slightly modified
------------
Thanks,
Srinivas
- Please mark as solution if your problem is resolved.
This is the complete Code :
When i execute the code ,the Account owner is not recevining any email.But my goal is to send an email to the Account owner.The code is correct or is that something im missing out .Any help very much appreciated.