Queueable Apex is essentially a superset of future methods with some extra features, released in Winter 15. We can say its a mixer of future methods and the power of Batch Apex! It is called by a simpleSystem.enqueueJob() method, which returns a job ID like Apex batch that you can monitor.
- Non-primitive types: Your Queueable class can contain member variables of non-primitive data types, such as sObjects or custom Apex types. Those objects can be accessed when the job executes.
- Monitoring: When you submit your job by invoking the System.enqueueJob method, the method returns the ID of the AsyncApexJob record. You can use this ID to identify your job and monitor its progress, either through the Salesforce user interface in the Apex Jobs page, or programmatically by querying your record from AsyncApexJob.
- Chaining jobs: You can chain one job to another job by starting a second job from a running job. Chaining jobs is useful if you need to do some sequential processing.
Example:
public class AddContact implements Queueable {
private Contact contact;
private String sta;
public AddContact(Contact con, String state) {
this.contact = con;
this.sta = state;
}
public void execute(QueueableContext context) {
List<Account> accounts = [Select ID from Account where BillingState =:sta LIMIT 200];
List<Contact> lstCon = new List<Contact>();
for (Account account : accounts) {
Contact clonedcon = contact.clone(false, false, false, false);
clonedcon.AccountID = account.ID;
lstCon.Add(clonedcon);
}
insert lstCon;
}
}
Thanks for sharing informative article on Salesforce technology. Your article helped me a lot to understand the career prospects in cloud computing technology. Cloud Computing Training in Chennai|cloud computing training chennai
ReplyDelete