The same way you cause emails to be sent when you create a Case
through any other Apex, by setting DMLOptions
.
There is documentation on setting DMLOptions, but the highlights of that page are...
Database.DMLOptions dml = new Database.DMLOptions();
// For sending emails to the person designated as the Contact for the case
dml.EmailHeader.triggerAutoResponseEmail = true;
// For sending emails to salesforce users of your org
dml.EmailHeader.triggerUserEmail = true;
// For sending emails to addresses outside of your org
dml.EmailHeader.triggerOtherEmail = true;
If you also have auto-assignment rules for cases that are created, you may need to set another DML option AssignmentRuleHeader.useDefaultRule
.
If you're only working with a single case, you can use the setOptions()
method of the SObject class to actually set the dml options.
Case c = new Case();
Database.DMLOptions dml = new Database.DMLOptions();
c.setOptions(dml);
insert case;
For lists of SObjects, you'd need to use the database.<dml method>()
method instead of just [insert|update] <list of SObject>;
. That method only exists for insert and update (not delete, undelete, or upsert)
Database.DMLOptions dml = new Database.DMLOptions();
Database.insert(myCaseList, dml);