You need to sign in to do that
Don't have an account?
SalesforceCrm AccountCRM
SendEmail failed. REQUIRED_FIELD_MISSING, Missing targetObjectId with template:
Can any one help me out with this error .
1)When im using mail.setTargetObjectId(c.CustomerSignedId); the system start throwing a 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 displayedHere 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.
Please refer this link for the answer :
http://salesforce.stackexchange.com/questions/118857/sendemail-failed-required-field-missing-missing-targetobjectid-with-template/118876#118876
All Answers
If you are using a template you have to specify the Contact, Lead, or User to send the message to. This makes sure the template merges the correct fields in. You are not able to use the setToAddresses with a template, so the targetObjectId is how you set who the email goes to.
Hope this helps you!
Best regards,
Jyothsna
When i use the the system throws an error
Invalid field contactId for SObject Contract
How do i get the contact id .When we are using the templateid ,we dont have an option to use the lookup fields as a merge field.
Any suggestion please.
Hi
We will require the ContactID, LeadID or UserID to use the email template.
There is workaround if you don't have the contact Id.
You can use create one dummy contact and use the id of that contact. once email process completed you can delete the contact or use SavePoint and Rollback to rollback the contact record.
Also there is another way.. you can query the template body and set email body with template body.
Please let me know if you need futher information
Thanks,
Please check the below link for your requirement.
http://opfocus.com/sending-emails-in-salesforce-to-non-contacts-using-apex/
Hope this helps you!
Best Regards,
Jyothsna
Please refer this link for the answer :
http://salesforce.stackexchange.com/questions/118857/sendemail-failed-required-field-missing-missing-targetobjectid-with-template/118876#118876