You need to sign in to do that
Don't have an account?
Ganesh Babu 8
setWhatId in send email causing "First exception on row 0; first error: INVALID_CROSS_REFERENCE_KEY" error
Hi All,
I am trying to send an email setting an Order record id in setWhatId method. It is throwing error "First exception on row 0; first error: INVALID_CROSS_REFERENCE_KEY".
Please help me to find the exact issue.
Thanks in Advance!
I am trying to send an email setting an Order record id in setWhatId method. It is throwing error "First exception on row 0; first error: INVALID_CROSS_REFERENCE_KEY".
List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>(); Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); list<String> toaddress = new list<String>{'gbabu.tg@xxx.com'}; mail.setToAddresses(toaddress); mail.setTemplateId(emailtemplt.Id); mail.setTargetObjectId(Id.valueof(uId)); //If it comment below code, it is working. mail.setWhatId(Id.valueof('8018E000000ghha')); mail.setSaveAsActivity(false); mails.add(mail); Messaging.sendEmail(mails);If I comment that particular line, it is wokring fine. As per the document setWhatId should accept Order record id, but it is throwing error.
Please help me to find the exact issue.
Thanks in Advance!