 Hello everyone. I'm Sanjay Gupta. I welcome you on Sanjay Gupta Tech School. This is my website, studysalesforce.com, video library to learn Salesforce. In this video, I'm going to demonstrate how you can create test utility class so that you can have bulk data and that bulk data you can create for separate Apex test classes. So one class can be called into various Apex test classes to have bulk data. So jumping into Salesforce org. So here you can see this code is implemented as a test class. And here I have two methods, one for testing insert operation and another for testing update operation. And at both the places I am creating bulk data. So what I'm going to do, I will be creating a test utility class. So I can call that class method here in this Apex test class. And if I want to call those methods in any other Apex test class, so that is also possible. So I'm creating test utility. So right now I'm creating it for account. So public static void, it will return list of account. Name will be create account records and it will be having some parameters like string name. These account count will be like how many records we want to create and Boolean is insert. Now here I need to create list of account. Now I'm going to implement a for loop. So in teaser equals to zero. I less than count. So count will decide like how many records will be created. Then account ACC equals to new account. Then ACC dot name equals to test plus I and ACC list dot add ACC. Now after this, we need to check if is insert. So if it is true, so here only you can insert this ACC list. If it is false, then you can return ACC list. So from where we are going to call this method, we need to pass these information. So here also I can place name instead of test. Name plus I. So whatever values you will be passing like name, number of records that you want to create is insert. Like if it is true, so record will be inserted here only if it is false. So account list will be returned and that will be updated wherever we are calling this method and then you need to insert. Right. So this way, okay, I need to remove this void because list of account is written type. So I'm saving this test unit utility. So I will be calling this method over here. So now I don't need this. I just need to this. And here I can call this directly. So test utility or this method here and passing test record count, let's say for and false. I don't want to insert because I need to assign the these billing city billing country and other information as well. Right. So here I am iterating this four times. We're moving this information. And here I'm going to use this ACC list of five. So common variables you can put in test unit utility common fields. And those you want to update later on you can do like this. And here you can insert this ACC list. So this way I updated everything here. Right. So base account records are created through this test utility like name is populated and all these information I populated here. And something is wrong. Okay, it is repeating. So this way it is working. Right. Rest of the code will remain same. Now here as well, I can use this. So I'm copying this. Pasting it here, removing this. So after insert this code will execute and it will update the records. So it should happen four times. So this way you can use this test utility class and its method. Now, if you have any other class, for example, we created one more example, like update account. So here also if you want this to happen. So what you can do here also like four records will be created. And ACC list of I dot active underscore underscore C equals to no. And ACC list of I dot rating equals to cold. So this way you can update. Sorry, you can insert this ACC list. So see what we did. We reuse this method create account records in two separate classes. So it is defined here, which is creating records. We, we called it here twice. We called it here as well to create four account records. Right. And if you want to put additional fields, so you can do. So here fields are different. So we populated those values and inserted. And here we are passing false. And here we need to put some different fields value. So we did that. So this way, if you create test utility class, so you can reuse this into several test classes. So this is also a best practice for some of the project. There's a requirement like you can create common test utility class and then you can call that to create records into separate Apex test classes. So I hope with this demonstration you understood how we can create test utility class. Also remember one thing here I created one method. But if you want to create contact record or any other objects record. So after this you can create any number of methods. So test utility class will be one and in that one class you can create multiple methods. Those will be reusing in several Apex test classes. So this way it works. So this way I demonstrated you like how we can create test utility utility class while creating Apex test classes. If you want to watch more Salesforce related videos, so visit studysalesforce.com or video library to learn Salesforce. Thank you for watching this video.