I have apex code that creates a scheduled job when a Contact is created. It runs 5 minutes after creation. It modifies something on the Contact, and when it does this, it shows “Last Modified” by me. How can I get this to run as our automation account name instead?
Here is the code:
String cronExp = System.now().addMinutes(5).format('s m H d M '?' yyyy');
System.schedule('Send SMS for New Contacts - ' + DateTime.now(), cronExp, new SendTwilioSMSNewContacts(contactIds));
- Convert that to a scheduled batch job submitted by your dedicated user. It’ll be bit pain to schedule it 12 times (to run at 5 past, 10 past…) but oh well. In job’s start() method put criteria for contacts created in last hour(?) that don’t have the SMS sent yet.
Or
- Read up about platform events. Convert your code to raising a platform event, then handling it with a trigger (you decide whether you want to send the SMS right away, couple seconds after contact creation or still schedule 5 min from the time the event is handled). Then read about “platform event subscriber config” (https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_platformeventsubscriberconfig.htm). Special file you need to craft and deploy, can’t make this in UI. Will let you specify whom the events should run as (and how many events handled in each transaction, which may be useful if you’re making callouts)
Salesforce doesn’t allow you to directly change the “Last Modified By” field to your automation account directly. However, To have the “Last Modified By” field to show your automation account instead of your name, you’ll need to ensure that your scheduled job execute under your automation account.