0

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 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);
         }
3
  • ahh here you need to set targetobjectId will be Account ownerId
    – Ratan Paul
    Commented May 6, 2016 at 9:08
  • @Ratan:Thanks for your response.But the targetObjectId (a contact, lead, or user).Can i use Account id in targerObjectid.Any Suggestion please. Commented May 6, 2016 at 11:00
  • Account ownerId means it is a user so you can use that Account's ownerid in targetObjectId
    – Ratan Paul
    Commented May 6, 2016 at 11:35

0

You must log in to answer this question.

Browse other questions tagged .