My implementation of Dan Appleman's Asynchronous Apex framework. Here's the link to the original presentation.
Assing the Manage Async Requests Permission Sett to your user and execute the following snippet:
// NOTE: this will update all your Accounts' Description field to "Updated: {execution time}"
Map<Id, Account> accounts = new Map<Id, Account>([SELECT Id FROM Account]);
insert new SampleJobAsync().prepareAsyncRequests(accounts.keySet());
NOTE: Due to the fact that Anonymous Apex enforces FLS, you need to have Manage Async Requests Permission Set assigned before executing the snippet above. You don't have to assign it to other users in order to use this framework.
Follow the below steps and use SampleJobAsync
implementation as a helpful reference:
- Create a new class that extends the
BaseAsyncHandler
- Implement
getRequestType()
method (NOTE: it should return a string that is unique accross all handlers) - Implement
execute(..)
method - Register the new handler by adding it to
requestHandlers
map inAsyncRequestQueueable
class
Then, to enqueu it, call:
insert new YOUR_NEW_ASYNC_JOB_CLASS().prepareAsyncRequests(SOME_SET_OF_IDS);
All pending and failed requests can be seen in Async Requests tab. In order to see this tab in Salesforce users have to be added to Manage Async Requests Permission Set.
In order to requeue failed requests, you have to find it in Async Requests tab and clear the Error Msg
field.
If something goes haywire and you need to switch off the processing of all requests, go to Setup > Custom Metadata Types
, then click Manage Records next to Async Request Settings
, edit the Default
record, clear the Is Async Request Processing Enabled
checkbox and save it.
See inline documentation.