1. We can call the apex code by creating object for the class (or) if the variables or methods are static then we can call with class name.
-
Apex Code in the trigger will execute automatically for the DML operations.
-
If you want to execute apex code on a specific time then we should write batch class.
-
With Batch Apex we can process maximum of 50 million records.
-
Batch Apex is asynchronous (execute in future context).
-
While writing the batch class we should inherit Database.Batchable interface.
-
Database is a built in global class which contains inner global interface.
2. What are the Batch Apex methods?
Since we are inheriting Database.Batchable interface we should implement all the method prototypes declared in the interface.
We should implement the following global methods:
-
Start: It will prepare the records to process and execute only one time.
-
Execute: It will take the records prepared in start method and split those records into batches and it will execute multiple times. For example if the start method is returning 1000 records then execute method executes 5 times if you don't mention the batch size (Default Batch Size is: 200). Maximum batch size is: 2000.
-
Finish: We can perform post commit logic like sending emails with the success or error information. It will execute only one time.