You need to sign in to do that
Don't have an account?
kevin chong
help! question on whatId when sending email
Hi mates,
I got problems when sending emails, the code like following:
Messaging.SingleEmailMessage mail=new Messaging.SingleEmailMessage();
mail.setTemplateId(emailTemplateId);
mail.setTargetObjectId(myContactId);
mail.setWhatId(customObjectId);
Messaging.sendEmail(new Messaging.SingleEmailMessage[]{mail});
mail.setTemplateId(emailTemplateId);
mail.setTargetObjectId(myContactId);
mail.setWhatId(customObjectId);
Messaging.sendEmail(new Messaging.SingleEmailMessage[]{mail});
The problem is on customObjectId, i know the whatId can be set to some standard object and the custom objects. But there are some custom objects cannot set to whatId. For example, i got a RFQ object, its fields are almost the same with another Schedule object. When setting the RFQ id, it works fine. When setting the Schedule id, i got a exception like following:
System.EmailException: SendEmail failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, Opportunity/Account ID: id value of incorrect type: a0070000009w4JMAAY: [WhatId]
So, is there a restriction of which custom object can be bound to the whatId field.
Thanks very much
Kevin
I have found the same issue while setting my custom object correctly using the setWhatId.
However after hours of trying to found the bug in my code I have noticed that actually the message refers to Activity WhatId field !!
Because by default the setSaveAsActivity has a value true, which saves the emailing as an activity - so... your costom object needs to be allowed for activity tracking. This is a setting in the custom object page.
So if you have this issue, enable your custom object for activities or do not save the activity.
-AT