[SalesForce] SaveAsActivity is not allowed with whatId that is not supported as a task whatId

While trying to create a custom business rule using Apex I got the error:

INVALID_ID_FIELD, SaveAsActivity is not allowed with whatId that is not supported as a task whatId.

…and found out that it was caused by the method setSaveAsActivity on my code, that was like:

msg.setSaveAsActivity(true); // "msg" is a SingleEmailMessage

What am I doing wrong here?

Best Answer

The error message can be a little confusing, but this error can be thrown if your main object (relatedTo in your template) doesn't have the "Allow Activities" option checked.

Checking this option will solve this issue.

This error message should be modified to something like "SaveSetAsActivity is not supported on objects that do not allow activities."

Related Topic