Can any one help me out with this error .
1)When im using mail.setTargetObjectId(c.CustomerSignedId); the system start throwing a error .
SendEmail failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Missing targetObjectId with template:
2)When im using mail.setTargetObjectId('00538000004bjrA'); the system start throwing a error .
SendEmail failed. First exception on row 0; first error: INVALID_ID_FIELD, WhatId is not available for sending emails to UserIds.: [whatId, 8004B000000Qmzi]
3)When i use mail.setTargetObjectId(c.OwnerId); ,
i get the email but the merge fields value are not getting displayed
Here is the Code which im using the Batch Class :
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.CustomerSignedId);
//mail.setTargetObjectId('00538000004bjrA');
mail.setWhatId(c.Id);
mail.setTemplateId('00X4B000000M3go');
mail.setSaveAsActivity(false);
mailList.add(mail);
}
}
Messaging.sendEmail(mailList);
}
Any Suggestion very much appreciated.