Recently, I ran into an interesting Salesforce edge case where I needed an Apex trigger to make a future call to Salesforce’s own REST API.
My goal was to essentially nudge certain Account records so that Salesforce Enterprise Territory Management would re-evaluate territory assignments after a specific field changed. A standard Apex update on the Accounts wasn’t enough to trigger the reassignment process. However, making a PATCH request to the REST API — effectively updating the records through the API instead of Apex DML — successfully caused the territory assignment rules to run.
Conceptually, this sounds straightforward. In practice, though, configuring a modern Named Credential using OAuth 2.0 so Salesforce can securely call itself can be surprisingly complex.
If you’d like to see the full step-by-step setup, including how to configure the Named Credential and perform the loopback callout from Apex, you can watch (or skim through) the video below where I walk through the entire process: