You need to sign in to do that
Don't have an account?
INVALID_SAVE_AS_ACTIVITY_FLAG, saveAsActivity must be false when sending mail to users
Here is portion of my code,
userId = Userinfo.getUserId();
email.setTargetObjectId(userId);
email.setBccSender(true);
email.setSaveAsActivity(true);
email.setUseSignature(false);
email.setSubject(subject);
email.setToAddresses(sendToAddresses);
email.setPlainTextBody(body);
Everything works fine when I set setSaveAsActivity to false. But I want to save it as an Activity when email is sent.
When I set setSaveAsActivity to true, I get the error, INVALID_SAVE_AS_ACTIVITY_FLAG, saveAsActivity must be false when sending mail to users
Does this have anything to do with which Id I am using to set in setTargetObjectId?
Can any of you help with this?
kindly add following line into your code
email.saveAsActivity = false;
thanks,
Correction - that's
mail.saveAsActivity = false;
email.setTargetObjectId(contactId);
This error will appear when you are trying to save the email as an activity, but are sending to a user. If you have a contact created for the user you could use that, if not another option is to use a generic contact and set the user email in the setToAdresses, just as you're doing.
https://developer.salesforce.com/forums/?id=9060G000000XamlQAC