[0:00]Hello and welcome everyone. Guys, so in today's video, I'll be talking about batch FX and all the interview questions related to batch FX. Uh, I have divided this video into four different sections and, uh, in the first section, I'll be talking about couple of basic questions related to batch epics, fundamental must to know questions. Uh, in the second section, I'll be talking about couple of advanced question on on batch epics theory. And then I'll be talking about couple of execution and and governor limits related question. And then at the end, I'll be talking about couple of scenario-based questions and how you can prepare those questions. Uh, all right, so let's get started. I've got my notes with me and the idea is that I might not be able to answer all the questions because I don't want to make this video very long. Uh, but I am always available on LinkedIn, so if you find a questions which I haven't answered and you need to know the answer of that, you can just ping me on LinkedIn and I'll be more than happy to have a discussion with you on that. Uh, but the idea is that you try to find the answer by yourself, uh, or if possible, you can do some practical work on your developer console. Uh, because by that way, you will be able to, uh, you know, remember that answer, uh, always. So, uh, with that, let's start the questions. Uh, the couple of basic questions, like what is batch epics, why we use it, uh, why it is better than couple of other asynchronous options available? Uh, what are the different, different methods available in the in the database.batchable database.batchable interface? Uh, and default batch size of a particular, uh, batch and how to schedule a batch. So, see, uh, batch epics is useful whenever you have a large data set to, you know, do something on, and, uh, when you can wait for it to be executed asynchronously. You don't need the result right now, most suitable for the weekly or overnight jobs, data backup jobs, or, you know, whenever you have to delete something periodically, uh, every month, whenever you have to deactivate users, uh, every month, whosoever is not using Salesforce license or not logging Salesforce, just deactivate them automatically.
[2:22]These type of the things, whenever you have to do something asynchronously on the on the larger data set, batch epics is most suitable in those kind of scenarios. Uh, but it's not like it is better than anything or better than other asynchronous thing, because everything has its own use case. So, future method and Cube Apex, they both are also very, very powerful tool, depending on their own own use cases. So, it's not like something is better than other, they both have their own use cases. Uh, why we use it to do something on the last data set? Interviewer may try to ask you like why you need batch epics when you have data loader already to do something on that bulk data, let's say delete something in bulk or something like that. So, you need to tell them that, see, data loader works on a very static data set, you need to create that data set separately and then you can do in the batch. You can create that data set dynamically, uh, query that data set and, you know, can change the condition as per your requirement. It, it basically a better way of doing those things. Batch is a better way of doing those those things, uh, and and data loader has its own use case. So, they are not related, although they both can work on the larger data set, but they are not, you know, interrelated. How to schedule a batch? You can schedule it from the UI as well as via code from the anonymous block from the schedule epics. So, you can use both. Uh, default batch size is 200, maximum is 2000. And different, different methods. So, see, database.batchable interface has three different methods and you need to implement that interface to get those three methods and then you need to define the body for them. So, uh, start method, finish method and execute method, the idea is that start method will give you the data set. Execute method will perform the operation on that data set and finish method will do all the post processing logic, whichever you need to do. And if you don't need anything in the finish method to do, you can just leave it empty, but you have to write the finish method, otherwise you will not be able to use, you will not be able to save that particular class. Then we will move on to couple of advanced question. Uh, the first question will be what is database.batchable? So, it's an interface which has three methods, you need to implement this interface in order to get access to those methods and provide the body of those methods. Uh, there are couple of other interfaces are also available, uh, which are separate questions. I'll I'll come to them. Then questions can be, what is database.query locator? It is basically a context variable which stores a lot of thing. One of that thing is job ID, uh, which you can use to get the track of your, the status, status of your job. So, job ID will be stored in the batchable context variable. Okay, what is interface? A very basic question related to programming, but as you are implementing an interface, you may get this question. So, you need to be very, uh, you know, you need to inform them if you, uh, if they ask you about the interface. Then they ask you, what is database.query locator? Uh, and how it is different from database.iterable? Uh, so database.query locator is basically returns the returns the data set to your, uh, to your execute method. Basically, database.query locator gives you, uh, gives you the asynchronous limits of data set, whereas I table, if you use I table, you will not be able to get the enhanced limit. So, 50,000 will be the limit with I table. And I table is also, I mean, I table, they may ask you why you use I table when, you know, database.query locator has everything advanced, larger than 50 million records and and why, why do you use I traders, I table? So, I table has its own specific use case. Uh, if you have used on I table, I mean, if you have used I table in a real time project, do you can explain that scenario? If you haven't, then you need to tell them that, uh, I table is used whenever you have to perform, uh, you know, some conditioning on the, uh, let's say, on the, let's say, you've got some aggregate result and you have to do some additional conditioning on that aggregate result, so you can use I table. The problem with I table, not the problem, but the limitation with I table is that you will not get the enhanced limit, so you will have 50,000 records limit. And, uh, with the I table, uh, your scope parameter will have no upper limit. So, just like, I mean, in the query locator, your scope parameter need to be defined with the limit, default is 200, max is 2000, with I table, there is no upper limit. So, you can, you can inform that thing. Okay, and then interviewer may ask you, see, you are doing a call out from execute method, but it is not happening, you are getting an error. What could be the issue? So, if you are doing call outs, you need to make sure that, you know, you are using the allow call outs interface, uh, implementing that interface, because without that your call outs will not go through. Uh, there is one other interface database.stateful. They may ask you why you use database, database.stateful. So, stateful basically stores the state of a batch and if you have a scenario where you need to make sure that you are counting the states or you are making sure that, uh, you know, state is is stored, then you use stateful. If you have worked on any scenario where you use database.stateful, you can inform them, otherwise you can just tell them that this basic information and, uh, just inform them that you haven't worked this in a real-time project, but would love to work on that. Okay, uh, how to track the status of your current running bad job? By the job ID, which is stored in the batchable context variable. So, with the help of that job ID, you can query the async apex job object and you can find the status of your job. Okay, async apex job object is also important thing, you may get a question from this. So, try to try to explore this object. Okay, uh, how to abort it, uh, and how to stop it, you need to check as well. Uh, you may get a question on that. I think these were the theory question I, uh, think you may get in in batch epics. And then let's talk about couple of execution and governor limit question. So, how many active bad jobs can run at a time? I think five. How many call outs are possible from batch? 250,000 per 24 hours. And if start method returns an I table, the scope parameter will have no upper limit. So, if you try to trick you on this, uh, let's say if you are using I table, what will be the default batch size or something or what will be the max value of that scope parameter? There is no such max value, okay? Can you, can you call another batch from a batch? Yes, you can do that from the finish method only. But can you call a future method? Uh, I think I have covered this question in any of my other video. You can call a future method, but not directly. You can do the call outs from the execute and then that call out call may be calling a future method class. Okay, can you call a batch from a trigger? Yes, you can call a batch from a trigger, but you need to see. There are governor limits all over the place and calling a batch from a trigger will not be a very good idea, because triggers run, I mean, batch will run in an asynchronous context. And trigger will will not, I mean, the performance will also decrease, you may get the governor limit. Can we call queueable Apex from batch? Yes, can we call schedulable Apex from batch? Yes. Can we publish an event from batch? Yes. This is a, this is one of the latest question I got on the batch epics. Can we call a, can we publish an event from a batch? Yes, we can do that. Try to, see, these questions are a bit tricky and sometimes interviewer will not ask these questions as directly as I am saying. So, they may give you a scenario and then try to trick you. So, the best option, the best way to remember the answer of these question is that try to create a batch, one queueable class, one schedulable class, try to, you know, call each other from here and there and then try to try to, you know, see the result of those things. If you do those things practically, you will be able to answer those things all again and again. And then what will happen is that every interview, before every interview, you need to go through these set of questions and then again, you know, need to remember and revise all those things. So, if you do it one, once practically, you will be able to answer all these things all again and again. And then let's talk about couple of scenario-based questions. Uh, recently one of my subscriber told me that he got this question. So, you have got accounts and then every account has multiple contacts and these contacts are duplicate contacts. So, uh, one account will have let's say five contact and two contacts have same email ID and you need to remove those contacts. So, uh, this was the question, you need to, you need to ask couple of follow-up question if you get these kind of scenario, because, uh, see, it, the approach should be like you should always try to get the accounts from the start method and then do the sub query about contacts in the in the execute method. Don't do sub query in the, in the start method itself and then ask couple of follow-up question if you're not able to understand the scenario. See, uh, future method, uh, you may get a lot of questions on the scenario, because especially, especially the experienced candidate will get scenario-based questions. So, make sure that you understand the scenario properly before answering that question. They may ask you to delete all the old cases. Okay, so if they ask you, okay, write a batch to delete all the old cases, how will you do that? See, you need to ask a couple of follow-up questions, first, what kind of cases we are deleting, how many, you know, what is, what is an old case? Are we actually deleting it? Are we also deleting the child cases? Are we deleting any active cases? So, a lot of follow-up questions are there, but mostly logic revolves around either, you know, getting the data set like how will you get the data set? Will how will you, you know, query that data set in the in the start method and how will you execute the logic? Uh, see, one thing is also very important is that database.save result. It basically gives you the success and error and you can define how many records were successful. Which of the records was successful. So database.save results, uh, gives you success and error, you can you can iterate over both and then can do the processing as per your need. It is a very important question and I've got this question multiple time. Uh, there is one question how to execute a batch every half an hour. So, you need to create a cron expression for half an hour and then need to pass that expression to your schedulable Apex. You may get couple of questions on this cron expression, uh, for every hour, for every half an hour, every 15 minutes, every 40 minutes. So, you need to work, I mean, couple of scenarios on cron expression.
[14:32]Okay, uh, can we get data directly in the in the execute, I mean, in the execute method without start method? So, basically what interview is trying is, he is trying to trick trick you, can we directly query in the execute method and, uh, you know, leave the start method empty.
[15:07]So, the idea of batch epics is that you get the data set from the start method and then you can do additional processing on that data on in the execute method. Not the full fledged data set on the on the execute method, so that is not a recommended thing to do. Okay, if the start method is getting data from the external object, how are you going to create that data set? Try that scenario. How to, can we modify a batch if it already has a pending job in the in the queue? Uh, how to bypass a validation rule, how to bypass a validation rule, let's say there is a validation rule on particular object and you are processing on that object and validation rule should be hit. Uh, so, how, how will you bypass it? Try that situation. Uh, so, basically, he may, he may, you know, kind of try to trick you that you can, you know, you can define a variable checkbox and then turn it on, it will bypass it and then turn it off in the execute method, something like that. So, he, he'll, he may basically try to trick with your mind. Okay, uh, can we write a batch with an empty start method? No, we do not need to write a start method empty, because that is returning us the data set and it returns something, so you need to return something. Can we make a call out from start method? Yes, you can make a call out from start method, but you have couple of governor limits defined and start method is basically to create the data set for you and that too a very large data set. So, doing call outs again and again from start method is not a good idea. So, see, these are the basic questions. I have got notes on these thing, you can just ping me on LinkedIn and I'll be more than happy to give you and discuss anything with you on the batch epics. Uh, thank you, thank you for watching this video and I'll come back to you with another, another video. Thank you.



