When manually changing Contact Owners in Salesforce, there is a checkbox that says "Send Notification Email." Is there a way to programmatically check that box when updating contacts using APEX?
Asked
Active
Viewed 892 times
1 Answers
0
You need DMLOptions
class and Database.update(records, options)
version of the call, not the usual update records;
. Something like
Database.DmlOptions options = new Database.DmlOptions();
options.emailHeader.triggerUserEmail = true;
List<Contact> contacts [SELECT Id FROM Contact LIMIT 10];
Database.update(contacts, options);
But it means failed update (validation rule, required field etc) will not throw an exception anymore. It's your job to examine what the Database.update
returned and decide if you have to rollback the transaction or maybe you're fine with "save what you can, swallow all errors"...
It's work ;) I don't like work. You really need apex code for this? Maybe a workflow, flow or process builder on ISCHANGED(OwnerId)
+ email alert would suffice?

eyescream
- 18,088
- 2
- 34
- 46