I am trying to send email to Contact through Apex class with SingleEmailMessage for Event assigned/updated for him, so used:
SetWhatID = Event.id;
It is failing to send email with below exception:
System.EmailException: SendEmail failed. First exception on row 0; first error: INVALID_CROSS_REFERENCE_KEY, invalid cross reference id
Can anyone help to understand the cause of this Exception?
Please find detailed code below:
email.setTargetObjectId(loggedInContactId);
email.setWhatId(objEvent.id); // Event Id
email.setSaveAsActivity(false);
email.setTemplateId(emailTemplate.id); // template Id with merged fields of Event
email.setToAddresses(new String[] {toAddress});
//Sending confirmtation mail
Messaging.sendEmail(new Messaging.SingleEmailmessage[] {email});