Queueable apex in salesforce

queueable apex in salesforce, queueable apex salesforce,sfdcpanda, sfdc panda, salesforce queueabel apex, salesforce examples, salesforce panda, panda doc, panda installation, salesforce amazon, salesforce video tutorial

Queueable apex in salesforce is more enhanced version of running apex code in asynchronous mode much like future method.

Heap size limit is higher for this queueable apex and it is more efficient because it runs on its own thread without depending on the system resource availability.

For making Extensive database operation and making a webservice callouts you can go for Queueable apex, Queueable apex don’t process batch and so the total number of batches and batches processed will always be zero.

Bonus points of having an Queueable apex :- 

  • You can chain jobs in parent child manner upto 50 in numbers in a single transaction, Like chaining one job to another job by starting a second job from a running job
  • You can use Non-primitive types like Sobject or custom Apex types.
  • Once we submit the queueable apex job, we can get the job id where we can monitor the progress from¬†AsyncApexJob object.

Apex Class Example :-

Queueable interface needs to be implemented for performing this queueable operation.

public class QueueableExample implements Queueable {
  public void execute(QueueableContext cont) {
  Contact c = new Contact(lastname ='kumar');
  insert c; 
  }}

To add this class as a job on the queue, call this method from anonymous window on developer console.

ID jobID = System.enqueueJob(new QueueableExample());

To query information about your submitted job, perform a SOQL query on AsyncApexJob object like below,

AsyncApexJob jobInfo = [SELECT Status,NumberOfErrors FROM AsyncApexJob WHERE Id=:jobID];

Chaining a second job :-

public class QueueableExample implements Queueable {
 public void execute(QueueableContext cont) {
 // Your processing logic here

// Chain this job to next job by submitting the next job
 System.enqueueJob(new SecondJob());
 }
}

Be the first to comment

Leave a Reply

Your email address will not be published.


*