You need to sign in to do that
Don't have an account?
Swamy P
System.EmailException: SendEmail failed. First exception on row 0; first error: INVALID_ID_FIELD, WhatId is not available for sending emails to UserIds.: [whatId, 800Z0000000Cixc]:
Hello Folks,
I was not able to send an email. I have added WHATID as well, below is my code:
mail.setToAddresses(ToUsersEmailIds);
mail.setCCAddresses(ccUsersEmailIds);
mail.setTemplateId(NOTIFICATION_EMAIL_TEMPLATE.Id);
mail.setTargetObjectId(newContract.OwnerId);
mail.setSaveAsActivity(false);
mail.setWhatId(newContract.id);
allMails.add(mail);
From some people i heard that i cannot add "setTargetObjectId" if i set "WhatId". But if i didn't set Targetobject Id it is throwing error, saying that required field missing.
Below is my exact error:
System.EmailException: SendEmail failed. First exception on row 0; first error: INVALID_ID_FIELD, WhatId is not available for sending emails to UserIds.: [whatId, 800Z0000000Cixc]: Class.ContractTriggerAfter.contractOwnerNotification: line 173, column 1
Please update me with your valuable solution,
Thnx in advance!!
I was not able to send an email. I have added WHATID as well, below is my code:
mail.setToAddresses(ToUsersEmailIds);
mail.setCCAddresses(ccUsersEmailIds);
mail.setTemplateId(NOTIFICATION_EMAIL_TEMPLATE.Id);
mail.setTargetObjectId(newContract.OwnerId);
mail.setSaveAsActivity(false);
mail.setWhatId(newContract.id);
allMails.add(mail);
From some people i heard that i cannot add "setTargetObjectId" if i set "WhatId". But if i didn't set Targetobject Id it is throwing error, saying that required field missing.
Below is my exact error:
System.EmailException: SendEmail failed. First exception on row 0; first error: INVALID_ID_FIELD, WhatId is not available for sending emails to UserIds.: [whatId, 800Z0000000Cixc]: Class.ContractTriggerAfter.contractOwnerNotification: line 173, column 1
Please update me with your valuable solution,
Thnx in advance!!
According to documentation, If you specify a contact for the targetObjectId field, you can specify an optional whatId as well. This helps to further ensure that merge fields in the template contain the correct data.
http://amitsalesforce.blogspot.in/2015/11/singleemailmessage-vs-massemailmessage.html
Sample code
You can try below code as well
mail.setTargetObjectId(newContract.id);
mail.setSaveAsActivity(false);
mail.setWhatId(newContract.OwnerId);
I'm sending email by using Contract object not the Contact object. While sending an email by apex it showing error messages that both are required.
To merge the data into template i have to pass record id, for that i'm just using WhatId but whatever u have given it seems wrong. i.e, setWhatId as OwnerId and setTargetobjectId as record record ID. Even i tried vice versa, but still i'm facing the same error.
Will you advice further more.
Yeah setWhatId is optional but if i wanted to merge fields which are in template, i have to pass whatId as well.
So I'm struggling with that field only.