Queueable Apex #inSalesforce

Queueable Apex #inSalesforce


This interface enables you to add jobs to the queue and monitor them. Using the interface is an enhanced way of running your asynchronous Apex code compared to using future methods.


Public class queueableActivateAccount implements Queueable{
    private List<Account> acct;
    private boolean flag;
    private String theDescription;
    public queueableActivateAccount(List<Account> accounts, boolean toggle,String theDesc){
        acct = accounts;
        flag = toggle;
        theDescription = theDesc;
    }
    public void execute(QueueableContext context){
        for(Account a:acct){
            a.Active__c = flag;
            a.sampleDescription__c = theDescription;
        }
        update acct;
    }
}


In anonymous window, try:

List<Account> accounts = [select id, Active__c, sampleDescription__c from Account];
Boolean flag = True;
String theDescription = 'ActivatedAccount';
queueableActivateAccount qa = new queueableActivateAccount(accounts, flag, theDescription);
System.enqueueJob(qa);


To monitor this:

Setup | Apex Jobs





Reference: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_queueing_jobs.htm

Comments