Posts

Showing posts from January, 2018

Queueable Apex

Queueable Apex is the simplicity of  Future Apex  and power of  Batch Apex . To write a Queueable apex class you have to implement  Queueable Interface . It provides a class structure that doesn't need  start  and  finish  method like Batch Apex. you can call apex class by using a simple method called  System.enqueue() . This method returns a job Id by which you can monitor it. Queueable Syntax-- public class ClassName implements Queueable{           public void execute(QueueableContext QC){                          //your awesome logic           } } Example- For example, we create a Queueable Apex class that insert contacts for Account Apex Class--   public class AddPrimaryContact implements Queueable{     private Contact ct;     private String st;      ...

Apex Scheduler

In order to schedule your apex class,  Salesforce  provides a Standard feature named   Apex Scheduler . To take benefits of Apex Scheduler first Write an Apex class that implements the  Schedulable   interface , and then schedule it for execution on specified time. Scheule Apex Syntax-- To run at the specific time your Apex class have to implement the Schedulable interface and then schedule an instance of your class to run at the specific time using  System.schedule()  method. global class ClassName implements Schedulabe{         global void execute(SchedulableContext SC){               // here your logic goes         } } Schedulable Interface contains only execute method with return type void and takes SchedulableContext Object as an argument. System.schedule() method takes three arguments, first one is a name for the job, second is CRON Expression that ...

Batch Apex

Batch Apex can be used to run large jobs that would exceed normal processing limit. If you have a lot of records to process, Batch Apex is your best solution to do this stuff. To Write batch apex class you have to implement  Database.Batchable  interface that consists three methods. 1. start method 2. execute method 3. finish method Here are the  signatures  of all three methods in this interface global class ClassName implements Database.Batchable<sObject> {     global Database.QueryLocator start(Database.BatchableContext BC) {         // collect the scope of records or objects to be passed to execute method     }     global void execute(Database.BatchableContext bc, List<sObject> scope){         // process each batch of records     }     global void finish(Database.BatchableContext bc){         // execute any post-proc...