 Hello, hi everyone. I am Sanjay Gupta. I welcome you on Sanjay Gupta Tech School. Today we have day 54 of the Salesforce Learning Bootcamp. And you can see today we are going to discuss one more type of asynchronous Apex and the type is batch Apex, right? So I hope yesterday I explained you how we implement future Apex. So you understood that well, and you did some practice also, like how how we can implement future methods with the help of asynchronous Apex process, right? And I gave you one assignment as well. So I hope you have practiced that. So for the folks, those who are joining this session for the first time. So if you want to know, like, if you if you join this session for the first time, and you want to follow all the sessions of the bootcamp, so you can just go through with this slide, which shows like, who am I and what experience I have, and what all certifications I have done. So you can just go through with this slide so that you can have enough insight. And here we have a session tracker. This session tracker is basically containing all the live recordings for those sessions which are already delivered. And here you can see day by schedule is available. So whenever there is a session, so on that day, I just provide a link here so that you can follow. So the link of this session tracker is available in the description of this video. And there is an exercise sheet. So if you click on this link, so you will find an exercise sheet. So in this exercise sheet, on daily basis, I just provide you some questions for practice. So you can just follow this as well. And I know like many folks are already following both the documents, but the new folks who find this video randomly. So this time just explaining for them, right? So these are seven virtual learning best practices that everybody needs to follow. So you need to proper focus on live session, take proper notes, write down doubts, ask them in QA part of the session. Don't miss any session as all the topics are connected. Practice each and every session with the exercises. So I already showed you the exercise sheet. And if you miss any session, or you want to ask doubts, so we have a telegram group, you can join that as well and practice these on daily basis. So do regular practice and become a consistent learner. And if we move forward, so here you can see the telegram group link is available, or you can say QR code is available. So you can scan and become part of this telegram group. And this is the timeline. So we are in week 15. So this is the second session of this week. And soon as in Kronos apex topic will also be covered. And next week, I will be delivering you the basics of visual force, right? And after that, you will be having integration sessions, which are very much important for you. So as per your demand, I just added visual force and integration in this bootcamp. Right? So just follow this. And if you have not followed Sanjay Gupta Tech School on these platform, so do follow my platform is available on YouTube that you are already watching LinkedIn, where I just provide all timely updates. Recently, I just shared admin Udemy course, free coupon code on LinkedIn. So I just share lots of material on LinkedIn. So you can follow me there. Instagram, like you frequently use so you can follow me there. I just provide all the notifications there and telegram, like this telegram channel, if you join, so there also you will receive timely notification and important things. And session tracker and exercise sheet links are available in the description of this video. So through that you can access. Okay, so share this channel with lots of folks because there will be more and more bootcamps in regular intervals and help me to reach 100k subscribers by the end of this month. So this is humble request. So if you want to show gratitude and support, so please help me to reach 100k subscribers. Thank you. And now jumping on to the topic. So today's topic is batch apex. So we'll be discussing about that. Right. So those folks who joined late or those who are watching the recording. So once again, welcome on the channel. So I just completed the brief introduction part. Now we'll be focusing on the topic like what is batch apex. So yesterday we discussed about how to implement future method. And while explaining future method, I just told you, like we use future method if we want to run any process as synchronously, like a separate thread will be there. And that thread will be executing the process in the background whenever resources are available. So generally, if you want to do web service call out, so we prefer future methods, right? But first of all, now we need to understand the requirement of batch apex, right? So what batch apex is? So basically, batch apex runs large jobs. It can process thousands or millions of records. So basically what we need to do whenever you want to work on your existing data, whenever you want to work on your existing data that that is already available in your org. So that data you can process with the help of batch apex, right? So with the help of batch apex, you can query that existing data and you can apply a certain process and through that process, whatever modifications you want to done in each record, you can do. So basically processes records as synchronously in batches. So for example, if you have 1000 records that you want to process, so basically 1000 records won't be processed altogether, they will be divided into different, different batches. So default batch size is 200. So if you queried 1000 records, so those 1000 records will be divided into five pieces of 200 records each light. So in first go, first 200 records will be processed in second go. Next 200 records will be processed. So this way your whole data will be divided into separate batches. That's why it is known as batch apex. And generally we use batch apex for data cleansing and archiving purpose. So data cleansing means like if you have unwanted data, you have some data or you have some records, those are available under particular object, but they are of no use. So you can just clean them or delete them. Archiving means like they will be deleted. So cleansing means it can be done like you are updating some records. So you are just populating any value or you are just blank, you are like removing some value from particular fields. So these kind of operations if you want to perform on existing data. So for that purpose, we basically use batch apex, right? So these are some introductory points related to batch apex. So how batch apex works. So this is very much important to understand. So like batch apex basically works. So here we have to implement an interface. So basically whenever you want to write any batch apex class, so you will be implementing an interface. So with the help of syntax, I will tell you what is actually the interface name. So right now you just need to understand like we have an interface that is predefined. And in that interface, we have several methods. So to implement batch apex, you need to implement that interface and whatever methods are available in that interface, you need to define them, right? So the execution logic of the batch class is called once for each batch of record that is being processed. So basically when you implement any interface in the batch apex, so there will be total three methods. One will be start one will be execute and one will be finish. So if you are processing on 1000 records, so start and finish will work once. But your execute method will be running five times if you have default batch size of 200, right? So the execution logic unit, you need to write in the execute method. Okay, so in upcoming slides, I will be discussing each method in detail as well. So we have three methods start, execute and finish. So execute method will be having all the business logic, and that execute method will be running again and again, it will be depending upon like how many batches or like how many records you have, those you will be processing. So each time when a batch class is invoked, the job is placed on the apex job queue and is executed as a discrete transaction, right? So it will be running asynchronously. So in the background, like it will be initiated and it will be running in the background. And in the foreground, you can just execute any other process also. So what are the advantages of implementing batch epics? So every transaction starts with a new set of governor limits, right? So this is simple like every transaction starts with a new set of governor limits. So like if you have different batches, so each batch will be having new set of governor limits. So there are less chances like your transaction will fail. And if one batch fails to process successfully, all other successful batch transactions aren't rolled back. So for example, if you are processing 1000 records, so if we take 200 as default batch size, so there will be total five batches, right? So those five batches from those five batches, if one batch is failing, so that one batch 200 records will be unsuccessful, remaining four batches 800 records will be successful. They won't be rolled back. So this is another benefit of using batch epics, right? So if one batch is failing, so it won't be impacting other batches, they will be executing properly if they have no errors, right? So this way, I hope you understood how batch epics actually works. Now, as I told you, we'll be implementing an interface. So interface name is database dot batchable. So this interface, we just need to implement and you will be having three methods there start, execute and finish. So in every batch epics class, you will be defining all three methods. And these three methods serves different purposes, right? So one by one, we are going to discuss about each method so that you can understand. Yeah, so Sachin is asking what's the benefit we will get if we process 10k records as synchronously. So Sachin basically, when we implement this batch epics and you want to process 10k records as synchronously. So like once you initiated your batch epics, so if you want to run it synchronously, so in that case, once that batch process is completed, then only you can initiate any other process. But here what will happen once you have initiated that batch epics? And suppose you are working on millions of records, so it will take lots of time. So what will happen? It will be running in the background and in the foreground, you can start working and initiate any other process as well. And later on what we can do this batch epics, we can schedule as well, right? So it will be running at particular time interval like weekly or daily basis at particular time. So this way you can just schedule your batch epics. So for real time example, like we have mobile data nowadays and we have daily limit for mobile data in India. And like for example, if you have purchased the plan and where you are getting one GB data on daily basis, so what happens at 12 midnight, whatever your data usage is, your limit is refreshed automatically at 12 midnight and for next day, you will be having again one GB data in your mobile phone. So that is done through scheduled batch, right? So batch is implemented. You don't need to run it manually. It will be executed automatically with the help of scheduled epics, right? So if you implement any batch epics, so that batch epics, you can just schedule as well, right? So we have three methods start, execute and finish. So we'll be understanding them. So Jenna is asking, can we increase the batch limit? So yes, we can, we can decide what, what should be the batch limit, but maximum is 2000, right? So default is 200 minimum, you can have one and maximum is 2000. So Sachin, you posted it correctly, right? Thank you for sharing your knowledge. So this is important to know. It is also an interview question like can we change the batch size? And what is the default batch limit? What is the maximum? What is the minimum? So everything you need to remember. Now if we move forward, so one by one, we'll be discussing about each method. So first method is start. So start method basically collect the record or objects to be passed to the interface method, execute for processing. So in simple terms, if I say start method basically collects the data on which we want to apply a process, right? So start method is called once at the beginning of the batch epics job. So this is important to know, like in entire batch epics, it will be called once, no matter how many records you have. It basically returns a database dot query locator object or an iterable that contains the records or objects passed to the job. So this we'll see with the help of example, when I will be showing you the code, so you will see will be generally using database dot query locator because it can give you a large number of records. So when query locator 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, right? So generally, we prefer database dot query locator if you want to retrieve the data in start method. And whereas with an iterable governor limit by SOQL queries is enforced. So generally, SOQL can query 50,000 records, so that limit will be applied. But if you go with database dot query locator, so that limit will be bypassed and you can query 50 million records. So generally, start method is used to fetch the data. Then we have second method which is execute. So it perform actual processing for each batch of data passed default batch sizes to 100 records, batches of records can execute in any order. It doesn't depends on which order they are received from the start method, right? So this is also important to know if you have created a five, 10, 15, 20, no matter how many batches you have created, they can execute in any order. It take a reference to the database dot batchable context object and list of S object or a list of parameterized time. So this number four we'll be understanding with the help of syntax. And when using database dot query locator use the returned list, right? So generally, we will be using database dot query locator to fetch the data and whatever data will be fetched through database dot query locator. So that will be returned through start method and it will be available in the execute method in form of list of S object, right? And last method is finished. So it is executed post processing operation. So once all your batches are processed through execute method. So it comes in the picture and it will be executed once. So it calls once after all batches are processed, right? For example, sending an email process can be implemented in finish method. So once all your batches are processed, so if you want to send an email, so that code you can write in the finish method. Okay. So this is the syntax that you need to understand. So first line says public class, then my batch. So this is the class name, then implements is a keyword. And then we are implementing database dot batchable. So this is a syntax, you need to use it as is. Then we have first method that is start, we have second method that is execute, we have third method that is finish, right? And each method you can see we need to pass one parameter of type batchable context, database dot batchable context and BC is a name of variable. It is available in each method, whether it is finish, execute or start. And start is having written type. So we have two options. We can use database dot query locator, we can use a triple as well. So it depends like how many records you are query basis on that you can prefer. And whatever data will be returned from the start method that will be stored here under this records. So list of P. So here you just need to specify the S object. Right? So this is the general syntax that will be using to implement any process with the help of batch epics. Right? So now moving forward, if you want to execute your batch, so what you need to do whatever batch class you are implementing, you need to create its instance. And then you need to call this execute batch method. And in that method, you can pass that instance that you have created. Okay. And the batch ID will be returned. So you can just receive it. And that batch ID, you can use to know the status of the batch. And if you want to pass the batch size, so this way you can change. So in above statement, default batch size will be 200. In below statement, default batch size will be 100. So if you want to manipulate batch size, so you can just pass it as a second parameter. So I'm just asking, we can't schedule as in chrono-sypics. So let me jump here. And I'm going to show you the chat as well so that you can see what all questions are here. So we cannot schedule synchronous epics. It is not possible. If you want to do that, so we have scheduled triggered flow. So there you can create a process. And other classes also, yeah, that also you can schedule. But for that, you will be using synchronous, sorry, you will be using scheduled epics process that is part of as in chrono-sypics, right? So through that, you can call any epics class that you can schedule. But if you are talking about code, so you need to use as in chrono process for sure. Yes, Sachin, if we need to process more records, so instead of going through synchronous, we can go through as synchronous process. So Mamta is asking how many times execute method called so execute method basically processes depending on number of records. So if you like Sachin mentioned a solution, so it depends on how many records are you are fetching. So if you're fetching or querying 1000 records, so there will be five batches because default batch size is 200. So in that case, your execute method will be executing five times. Yes, really, after completion of lightning web component, there will be deployment related sessions as well. Okay, so I hope you understood the basic process of batch epics. So moving moving forward. So in previous step, like the batch ID which we received, if you want to know the status of your batch epics, so you can apply this as SQL which says select ID status job items processed, total job items number of errors from async epics jobs where ID equals to batch ID. So if you execute this as SQL, so you will be getting the information about your batch epics. And yesterday, I showed you like through UI also, you can see the status. So we can utilize that functionality as well. Now I'm going to give you a small demo where I will be implementing a batch epics. And we'll show you like how it will be implemented and executed. So we'll be implementing its test class as well. Okay, so jumping here and I'm going to implement it for you. So basically, what I'm going to do, I'm going to implement a batch epics, which will be querying all the opportunity records and all those opportunity records will be updated. And on opportunity we have a field called lead source. So I will be updating that lead source for all the opportunities. So basically what I'm going to do, I'm going to create a opportunity processor, right? So public class opportunity processor. And here I'm writing implements database dot batchable. And here we need to pass s object, right? After that, I'm passing one more interface that is database dot stateful, right? So now I'm creating one integer variable that is record count. So this record count is initially zero. And for this record count variable, we actually implemented this database dot stateful. So I will be explaining you the purpose of this database dot stateful. So right now you can just ignore it. You need to focus on this database dot batchable s object. So if you want to convert your apex class into batch epics, so you need to implement this interface, database dot batchable, right? And here we have the we have created this variable record count. So I will be explaining the use of this. But before that, I'm going to implement all three methods, start execute and finish. So public then database dot query locator, then name of method is start. And here we need to write database dot batchable context and variable name can be anything, right? So this is the name of method start is the name of the method. And this parameter you need to pass because this is this start method is basically available in this interface. And it is predefined. That's why we need to pass this parameter here of type database dot batchable context. Now here we are writing return database dot get query locator and here I'm going to write this SOQL, right? So basically what I'm doing I'm just querying ideal lead source of all the opportunity cards. And I'm not storing it into a list. I'm just writing the statement with return. So the start method will be returning the data which we are going to query with this SOQL. Right? Now I'm going to define one more method that is public void execute. And again, here I just need to pass this as a parameter. So I can just copy and paste it. Now here I need to use one more parameter that will be list of opportunity. And those opportunities I'm just storing into O PPS. So this is a list and whatever data will be returning from here that data will be automatically stored in this O PPS variable. So this list name can be anything. The s object will depend like what type of data you are querying from which object you are querying the data, right? So this way you can define these type and name. And here we need to implement the process. Right? So here I can apply null check as well. So if not O PPS dot is empty, if it is not empty, so there may be chances like if you query some data and there is no record available under the object. So for that purpose, you can apply null check. And here what you can do you can apply for opportunity. So what will happen? We have all the opportunities here in this O PPS. So this opportunity list will be traded one by one and data will be available into this O PPS. Now what we need to do this O PPS dot lead source, we need to modify. So what I'm going to do for all opportunity records, like whatever opportunity records are available under the object, I just want to update all opportunity record lead source to web. So this is my requirement and this I'm going to show you for a demo purpose, right? In real time, what we do we can apply where clause here we can apply some limits so that particular record will be queried and basis on that we will be applying the process. Okay, so once this loop is completed, once this loop is completed. So here I can write update O PPS and I'm just writing record count equals to record count plus O PPS dot size. Now we need to understand why I wrote this statement. So basically what I'm doing, whatever opportunity size is what whatever number of records are available in this O PPS list. So that size will be added into this record count. So I already told you if you are working on large number of records, so this execute method will be executed many times. So every time what will happen, this record count will be counted will be counting total number of records which are available in this opportunity list. So for example, you are querying 900 records and default batch sizes 200. So first batch will give you 200. So 200 will be added into record count. Then for next batch when this execute method will be executing. So this record count will be having value as 400 because prior it was having 200 and next time it will be having new 200 added, right? And this is happening because of this database dot stateful. So if I remove this database dot stateful, so for each execute method record count will be initialized with zero. If I remove this database dot stateful interface, so what will happen this record count variable will be reset zero will be reset as zero whenever execute method begins its execution for individual batches. Now if you want to preserve the value of record count variable for different different batches. So for that purpose, you need to write this database dot stateful interface, right? So this is the purpose of this method. Now after this, what we need to do, we need to implement one more method that is public void finish. And here also we need to write database dot batchable context BC. And here I'm going to write system dot debug. So as you know, finish will be working once finish will be working once. So here what we can do we can just show the final value of record count. So the number of records which which you are processing. So the total number of records will be available here because we are preserving the data of record count variable every time whenever execute method is executed. Right? So this way you can implement your batch apex. So this execute method is important, because here you will be implementing all the business logic. In start method, you will be querying all the data on which you want to apply the process. And in finish, you can write the statements whatever you want to execute once all the batches are processed with the help of execute method, right? So this way we can implement it. Now what we need to do, we need to execute this, right? So right now, we are not going to schedule it. So we need to execute it manually. And for manual execution, what we need to do, we just need to go to anonymous window. And under anonymous window, I will be writing some code and it will start execution. Before that, I'm going to take you under apex jobs. So here you can see we have apex jobs jobs. If you want to search for apex jobs, so here you can search under setup. So apex jobs option will be available and right now we have one apex jobs that we executed yesterday. Now what I'm going to do, I'm going to run this batch apex. And here you will see one more entry. Picks will be so you will see one more entry available. Okay, so now I'm going to execute it. So I'm just opening anonymous window. And here I will be writing few lines of code so that you can understand how our batch apex can be called. So there is little bit internet fluctuation. So I'm just repeating whatever I explained. So I just showed you how you can search for apex jobs. And once you find apex jobs, so what you can do here, you can see whatever batch apex you have executed, right? So that entry will be available here. And here in anonymous window, I will be writing the code so that you can understand how it will be executed. Okay, so here I'm going to write the code. So first of all, what you need to do, you need to create an instant of sorry, instance of your class. So generally, what we do we create static methods, and we call those static methods with the name of class. But here, we are not having any static method, because it is different process. So you need to create an instance like this. And in initial sessions, I told you like, I explained you how we can create instance. So this is the same if you don't have any static method, so you can create instance of the class. And here I'm going to call it like this database dot execute batch. And here you can pass this value. Okay, so with this your batch will be executed. Now before executing this batch, I'm moving here under opportunities, right? So under opportunities here, I'm going to select all opportunities. And I'm going to add a field. So I'm going to add the field as lead source. So from here, I'm selecting lead source and shifting it in the beginning and clicking on save. So right now you can see lead source is different for records for few records, it is blank for few records, it is having a different but now when I will be executing the batch, it will be web for all the records, right? It will be web for all the records. And here you can see we have lots of records. We have lots of records, so total 267 records we are having. So I guess total number of batches will be two because default batch size is 200, right? So now I'm going to execute this so that you can experience how batch actually walk. So moving to developer console here we have anonymous window. These two lines are available. So I'm just clicking on execute. So both the lines will be executed. And here it is showing some error. Execute batch. Okay, it is showing some error. So I'm just going to have it again. Okay, I just found the mistake. Basically, what I did, I didn't save the code. So if you see here, it is showing some asterisk. I didn't save the code. So what I need to do. First of all, I'm just going to save this. So clicking on the class and pressing control s. So here you can see it is saving. Now it is saved. And I'm going to click on execute once again. So it is now executed. Right. So before start executing your code, you need to save whatever batch epics you have implemented. Right now I'm moving here first. So I'm refreshing this page. Apex jobs. So here we have one entry right now future method. But now you will see two entries. We have one more entry for batch epics. Right. So it is for second of May 739 a.m. You can see job type is batch epics. It is completed because we have less number of records. Total batches to because 200 more than 200 records were there. So two batches are processed failures are zero. And you can see other details are available. Okay. Now if we go here and if I pin it and refresh the opportunity tab. So here you can see all the records are having lead source as well. All the records. So this way if you want to mass update your existing records basis on particular SOQL so you can use batch epics for execution. Right. Now you might be thinking how we can pass batch size manually. So right now default batch size is 200. If you want to modify it we can do but before that I want to show you one more thing. So in finish method we use this statement. Total records processed. So if I go here under locks. So here I just need to open these one by one so that I can find a debugs. So I just need to click on debug only and here you can see total records processed is 267. So it is showing total number of record like 200 records process through one batch and 67 records process through another batch and why it is showing 267 because we implemented this interface database dot stateful. If you remove it so it will show you 67 only. So first batch 200 will be counted but when second batch will be started its execution. So record count will be initiating with zero. If you don't write this database dot stateful interface. Right. So I hope you understood everything whatever is written over here. Now I'm going to modify it. So I'm passing 100 here or let's say 50. I'm passing 50 here. So we have 267 records. Right. So total six batches will be there. Total number of batches will be 600. Okay. So again I'm going to execute it and moving here this page I'm going to refresh. So you will see one more entry here. So you can see one more entry. So earlier we executed it at 739 AM second execution happened at 742 AM. And here you can see total number of batches six because we provided batch size as 50. Right. So this way you can manually manipulate the batch size but default is 200. If you want to provide this batch size manually you can do very well. Right. So this way I hope you understood. Now I'm going to take your questions. So Abhishek is asking when we use trigger and when we use batch class. So answer is simple if you have new newly created or you are updating your record from UI you are deleting your records then trigger executes. But if you are not doing anything on your record and you want to do mass operations on your existing records then we implement batch class. So Sunil I already explained you database dot query locator and iterable. So if you use iterable so SQL limit will be applied but if you use database dot query locator so that limit won't be applied and you will be able to query 50 million records. So in our example we used a database dot query locator as a return type and to get the data we are using this method get query locator. So generally we prefer this notation only. Yeah. So start and finish only runs once and execute will run in batches until all the records passed from start are done. Yeah. Exactly. Yeah. So basically whenever there are large number of records and you want to do some operations on those existing records so every time we go for batch epics. So next question is when you pass the second parameter that is 50. So if we want to split the batch into multiple for that we have to use the second parameter or not. And yeah it is an optional parameter. So Jenna you can see in first execution I didn't use it. So I just passed one parameter right. And in second execution I wrote it like this. So this batch size is optional if you provide so accordingly batches will be processed. If you don't provide so default batch size will be 200. Okay. So with this now I'm moving further. So now what we need to do we need to understand how we can implement it's test class. Right. So I already explained you the process like how we can implement batch epics how we can execute how we can monitor. So everything I explained to you. Right. So now what we need to do. So here we monitored here we saw the results and from here we implemented batch epics through anonymous window we actually executed and later like on Thursday you will see how we can schedule batch epics as well. But before that I'm going to create new class and will be implementing its test class. So opportunity processor test. So it will be annotated with at the rate is test I'm saving it. And for practice purpose if you go to this document so here one batch code like batch code you need to implement for this requirement. So for all the accounts where billing addresses populated you need to copy that billing address to all the related contacts mailing address. Right. So this you need to do with the help of batch epics you need to write its test class as well. Okay. So I hope you are enjoying this exercise document those who are following this bootcamp and it is very important if you want to become expert in Salesforce and it is kind of your internship. So if you are following this bootcamp from the beginning so you can consider this like bootcamp your internship because in the internship also industry experts teach you few topics they give you assignment tasks and you implement them. So you can consider this bootcamp as your internship. So moving forward now I'm going to implement the test class. So here at the rate is test for the method so I'm writing private static void test batch class. So basically here we need to create the data. So we processed batch on opportunity. So I'm going to create opportunity list here. So in test class first of all we'll be creating the data. So here I'm going to create 200 records. So here we need to provide the required field value. So test I is opportunity name then we need to provide close date. So close date I'm just writing system dot today. Then we need to provide the stage. So stage name I'm providing as prospecting. Right. So this way I'm just creating the data. So here you can see total 200 records will be created. Right. 200 records will be created and those records will be having some data. After completion of this loop I'm just writing insert OPP list and here I can write test dot start test so that we can have fresh government limits and after this insert what I need to do I just need to initiate that batch. Right. So I just need to initiate that back. So what we'll be doing. So from here I'm just copying this and I'm going to paste it here. Okay. So you can see first of all I just inserted all the opportunities then opportunity processor this class instance I'm creating and then I'm calling this that execute batch method where I'm passing the instance and here like we will be processing it for 200 records. So in test class whenever you test your batch so you can provide batch sizes 200 right and here I'm going to write test dot stop test. Okay. So this way like first of all we created the data then we called batch epics now what we need to do we need to query opportunity records so that we can verify whether opportunity records are updated or not. Right. So here we created 200 records and through that batch epics all 200 records should be having lead sources web. So what I'm going to do I'm going to create list of opportunity naming it as updated opportunities. Now here I'm going to query from opportunity here I'm going to query from opportunity where lead source equals to web. Right. So what I did I just queried all the opportunity records where lead sources web. Right. So you can see I'm querying the opportunities where lead sources web. So we created 200 records here then we executed a batch. So batch will be updating all 200 records. Now here I just need to apply a system dot assert equal and I just need to check the size of this list updated opportunity if it is equals to 200 it means 200 records are updated with lead source as web if it is equal so this will pass if it is not passed then like your logic is not correctly implemented. Okay. So I'm just saving the code and it is having some error. So here I just missed this bracket. So yesterday I also did same mistake. So now you can see the code is saved permanently and this test class is available here. Now moving to test tab clicking on run test. So it is failing. So let's see what is the error. So assertion is failing expected 200 and actual is zero. So there is some mistake in the code. So let me just check it again. So I'm just checking what mistake I did. So we inserted the opportunities then opportunity process instance we created then in database dot execute batch we are passing it. So the code seems correct. Okay. So here I'm just changing it. Although it is case insensitive but here I'm just changing it and trying to execute it once again. Again it is failing. So let me just check. So I'm just checking why it is failing. If you find out any mistakes or let me know in the chat. Yeah. So I think wamshi picked my mistake. So what I did I just created these opportunities but I didn't add this opportunity to opportunity list. So thank you for those who pointed out this error. So here I just need to write OPP list ad and here I need to add opportunities. So this is a statement I missed. So inside loop I just need to add all the opportunity instances into OPP list. Now opportunities will be inserted and it will run. So again I'm just saving the code and so this happens sometimes because I just wrote the code and I was unable to find out the bug. So with your help I'm able to complete it now. So I'm just clicking on run test. Okay. It is again showing some error. So let me see what is it now. So insert failed. Okay. So here it is asking please populate amount on opportunity. So there is one validation available which is saying us to populate opportunity amount as well. So what we need to do we need to populate amount also. Right. So I think this time it will run successfully. So again I'm clicking on run test. Yeah this time you can see your test classes passing successfully. Right. And if I go here and check the code coverage so it is 100% all the lines are covered which we implemented. So this way whenever you want to write your batch epics or just implement the batch epics and through this test class this way you can test whether it is working fine or not. So first of all you need to create the data and then insert that then execute your batch and then query the records which you modified or updated and then apply the assert operation. And I hope you understood why assert is important because I just forgot to write the statement. So I just found out this error with the help of assert equal. If I didn't write assert equal so we won't be able to verify whether code is working fine or not. So this is best practice to write assert equals in each code. So this way I hope you understood how batch epics works how we can implement how we can test it through anonymous window how we can monitor it how we can view the updated values on UI and how we can implement the test class. Right. Now I'm moving to the chat so that I can take your questions. So Jenna I already told you like second parameter is optional. Yes Jenna we can change batch size limit from 200 to 500. Yeah. So you just need to pass that second parameter but that the actual default size that is 200 that you cannot change. So Venkatesh I already explained how to write test classes for if else condition. So if you have if else condition so in that case you will be implementing two test methods in your test class. Right. So that I already explained you. Yeah. So there is one question when to use private public and global. So generally a private we use if you want to use that method or variable inside the class. So if you want to restrict method or variable into one class then you use private. If you want your method can be accessible outside the class then you use public and if you want your methods will be accessible outside the namespace outside the application then you can use global. Right. So Venkatesh this scenario I already demonstrated when we were discussing about test class so you can just go through the test class sessions you will understand how we can implement positive and negative test cases for if else conditions. Okay. So this way I hope everybody understood whatever I explained today and this way batch epics is completed and tomorrow we will be discussing about cueable epics and day after tomorrow I will show you how we can schedule epics classes with the help of scheduled epics. So this is it for today's session. If you have more question you can ask otherwise you can go and do some practice and at nine PM we'll be having cybersecurity bootcamp. So do join that and please share this channel link with with the folks. So from next month I will be starting new bootcamp that will be on C and C++ programming. So all the beginner those who are related to college freshers switching from non IT to IT if they want to begin their coding journey. So C and C C++ programming languages are based for beginners. So that bootcamp will be running for two to three months. It will be starting from next month like June 1st week. I have already created a telegram group for that. So you can just join the telegram group if you want to receive timely notification. Right. So there are a few more questions coming up. So Mamta is asking can you explain so bulkification is simple. So whenever we need to create lots of reports so here we are creating bulkification. So this loop will be written 200 times 200 opportunities will be created through this statement OPP and all the opportunities will be added into this opportunity list. Right. So Charlie I already showed you like this batch of topics we implemented to change the existing lead source value to web for all the records. It is working so you can implement it in your system. So whatever records you are having already in your org so all those records lead source will convert into web. So Navin we are not updating lead source prospecting prospecting is basically stage. So here we didn't provide lead source lead sources null blank and then it will be updated to web. So here we didn't provide lead source any value. Lead source is a pick list and that will be having none. So once that batch will be executed so all the records will be having lead source as well. Venkatesh the topics which I already completed I won't be repeating them because I have limited time. So you can just go and check the test class sessions. There you will get to know for if else how we can write two different methods. Thank you for appreciating my efforts. So I'm trying to explain everything in detail so that I can answer all of your questions. So I'm doing this for the community so that you can learn things properly. So this is it for today's session. We'll see you tomorrow with new topic that is queueable epics. Thank you everybody for joining this session. Keep learning keep motivating yourself and keep providing some feedback for me. So from few days you have not provided any feedback and reviews. So I would request please provide some feedback and reviews so that I also can get some motivation and please show some gratitude and support and help Sanjay Gupta Tech School YouTube channel to reach 100k subscribers on YouTube by the end of this year. Right. So right now I am running two boot camps one on Salesforce and one on cybersecurity. From next month there will be one more bootcamp and I'm also planning to have one more bootcamp on Salesforce cloud. Right. So there will be three four boot camps running in parallel at different times. Right. And gradually you will be having a lot more. So I'm working on different different concepts. So wherever things are working out so I will be sharing all the information with you so that you can get benefited. Thank you everybody for joining this session. See you tomorrow at same time.