 Let's understand batch epics in Salesforce. So batch epics is basically a type of asynchronous epics which runs in the background. So batch epics runs large jobs. It can process thousands or millions of reports. It processes records asynchronously in batches. So the purpose of batch epics is like, if you want to clean your data and if you want data archiving, then batch epics is probably best solution. So what batch epics does, it divides large number of records into multiple batches and those batches are run one by one and the same business logic is applied for all the batches. So how batch epics works, the execution logic of the batch class is called once for each batch of records. That is being processed. So one logic will be applied for each of the batches. Each time when a batch class is invoked, the job is placed on the epics job queue and is executed as a discrete transaction. Now, what are the advantages of creating separate batches? So every transaction starts with a new set of governor limits. If one batch fails to process successfully, all other successful batch transactions are unrolled back. So these are two major advantages of using batch epics in Salesforce. Now, coming onto the syntax, like how we can implement batch epics in Salesforce. So batch epics class must implement the database.batchable interface and include the following three methods. So this is important to write database.batchable interface with the class that you are implementing as batch epics. And if you are implementing the interface batchable, sorry, database.batchable, then you need to define these three methods, start, execute and finish. Now we need to understand what these three methods do. So first of all, let's understand the use of start method. So it collects the records or objects to be passed to the interface method executing for processing. Start method is called once at the beginning of a batch epics jobs. So whenever you are initiating any batch epics execution, so start method is executed only once, it returns a database.querylocator object or an iterable that contains the records or objects passed to the object. So this is important. So it basically returns anyone, like database.querylocator object or an iterable. And these will be having records on which processing will be applied. When querylocator object is used, the governor limit for the total number of records retrieved by SOQL queries is bypassed and 50 million records can be queried. So this is the use of query locator if you want, whereas when an iterable governor limits by SOQL queries is enforced. So if you use iterable, then governor limits are applied and if you use query locator, so in that case, SOQL queries limit is bypassed and 50 million records can be queried. Now next is execute. So this is second method and it is important because here we need to define the business logic that will be executed when batch epics runs and it will be executed every time for a batch. Like if you have 20 batches, so it will run 20 times, one time for each batch. So it basically performs actual processing for each batch of data passed. Default batch size is 200 records. Batches of records can be executed in any order. It doesn't depends on which order they are received from the start method. It takes a reference to the database.batchable context object and a list of S object or a list of parameterized type. When using database.query locator, use the returned list. So these are the things that you need to remember while using execute method. So like when I will be explaining the demo, so you will understand how do you start, execute and finish method. So next we have finished. So let's understand this as well. So it executes post-processing operation. It calls once after all batches are processed. So start also execute once whenever batch epics is initiated and finish will be executed whenever all the batches finish their processing. For example, if you want to send an email after completion of the process, so you can write that code in the finish method of batch epics. Now this is a simple example. So I will be implementing the example in developer console as well. So let's understand this first so that you can see all the syntaxes of start, execute and finish methods. So public class, my batch, so my batch is the class name, then it is implementing database.batchable interface, then public database.query locator or iterable as object. So you can use anyone then start method, then database.batchable context, BC. So this you need to pass as an argument and here you need to write the code. So as for the comment, it collects the batches of records or objects to be passed to execute method. So whatever records, whatever collection you will be creating here, that will be passed to this second method which is execute. So on those record collection, basically processing will be done. So second method is public void execute and parameters are database.batchable context BC and list of records. So here you need to write the business logic. So process each batch of records. Then we have a third method which is finished. So public void finish database.batchable context BC. So this database.batchable context we need to use in every method. And here we can execute post processing operations. So this way with the help of this example you might have understood how to draft your batch epics class. Now after implementing your batch epics class how to invoke the batch class? So first you need to create the instance. So my batch is the class name. Then my batch OBJ is the instance. Then we are creating memory for this. Then ID batch ID equals to database.execute batch and my batch OBJ. So this way you can call batch epics class. And when it is initiated so batch ID will be available in this variable so that you can query this variable and you can see the different properties related to that ID. Then you can pass batch size if needed. So by default batch size is 200 that I already explained but if you want to change that size so this way you can pass two parameters. My batch OBJ and batch size. So let's say if you have 500 records so five batches will be created of 100 records each. If you don't pass 100 and if you have 500 records so in that case three batches will be created two for 200 records and one for 100 records. So this way there are two methods of like executing batch epics. Now each batch epics invocation creates an asynchronous epics job record. It helps to track progress of the job. So how you can do that? So in previous slide you saw like we receive a batch ID so how we can query that? So you need to create instance of our sync epics job then select ID status, job item persist, total job items, number of errors from a sync epics job where ID equals to this batch ID. So that's why we received that batch ID and stored into batch ID variables so that we can query and we can see different properties with the help of this query. So in next video you will see how we can implement batch epics code and how we can implement its test class.