 Hello, hi everyone. I am Sanjay Gupta. I welcome you on Sanjay Gupta Tech School. So today is day 52 of the Salesforce Learning Bootcamp. And in this session, I will be discussing about Apex test best practices. And prior to discussion of best practices, I will be explaining you what is at the rate test setup and how we implement data factory class for testing Apex classes. So these two are new concepts like yesterday we saw how we can implement data in our test class in different methods. So through test setup and through data factory, you can create data once and you can reuse it as many times as you want. Right. So these topics we will be discussing in today's session. So before moving to the session, I just want to welcome everybody. So hello and welcome. So I can see Nana, Sojit Akshay. So hi, hello. Good evening. And welcome to the show. And today I will be completing this test class topic. And I hope you are enjoying all the sessions, right? So today also we'll be having some discussion basis on whatever I will be demonstrating. So whatever questions you have, you can just type in the chat and I will be answering your questions. So I'm just waiting for a couple of more minutes so that more folks can join. And then I will be starting the session. So meanwhile, like I'm jumping onto the chat, let's see who are greeting me. So yep. So I can see Nana, Sanjay, Akshay, Praveen, Sikandar, Pooja, little world. So hello, hi. Welcome to the tech school and jumping to the next slide. So if you are watching this session for the first time, so you should know about your instructor. So just go through with this slide. It will tell you everything about me. And if you're watching this day 52, so you can just start with day one and all the admin and development related stuff you can go through, right? So you need to focus on all these virtual learning best practices. If you want to really learn Salesforce admin and development stuff, right? So do regular practice, don't miss any session, practice all the exercises, those are available. And like in this practice sheet, I just added a playlist link. So to practice apex trigger and test classes. So this playlist link is available. So you can just go through with all the videos where I am just explaining how trigger is implemented and how you can implement test class for that particular trigger, right? So you can just go through with this playlist and you will you will be having all the insights, right? And consistency is the key. So please do regular practice. Don't think whether you are having any offer or not if you're a fresher, or if you are experienced professional, then also you need to do consistent practice. Because if you do consistent practice, then in interview, you will be explaining concepts differently, right? Because if you are practicing things practically, it means you know how it is actually working, right? So moving forward, so in today's session also I will be explaining the topic will be doing the demo and I will be answering your questions. And if you want to become part of a self help group where people are helping each other. So that group is created for all the beginners, those who are Salesforce enthusiast and they are learning Salesforce. So you can just scan this QR code and you can become part of that group. If you have not, if you are already part of that, so you can utilize that group. And this is the upcoming days bootcamp timeline. So like today, Apex test class will be completed. And Jana is asking about like, do we have one more session? So tomorrow's session I will let you know. I need to prepare some content. So if that is ready, then I will be delivering that tomorrow. Otherwise next session will be on Monday. So I will update you in the telegram group about that, right? And next week, we'll be discussing about as-in-pronunciation Apex. Then on your demand, I just included visual force. So basics of visual force, we'll be discussing in the session. And then two weeks, we will be discussing about integration, right? So this is the upcoming plan in front of you. And just follow Sanjay Gupta Tech School on YouTube, LinkedIn, Instagram, telegram, so that you can receive timely updates. All the important links like session tracker, exercise sheet, all these important links are available in the video's description. So follow Sanjay Gupta Tech School if you want to like attend different, different bootcamps for the free. And as I promised you like sales force admin and development bootcamp is going on and cybersecurity bootcamp is also going on. And let me tell you one thing like from next month, I will be starting one of the Salesforce Cloud Bootcamp. So name of that cloud I am not revealing right now that I will be sharing in the first week of next month. But from next month, you will be having one more bootcamp that will be related to particular cloud, right? So we have learned so far lots of admin and development thing. So I just thought like let's introduce one cloud specific session so that you can understand that terminology as well like how basically in particular cloud things works, right? So I'm planning about that. Let's see what topic I pick other than Salesforce admin and development, right? But it will be specific to particular cloud. So right now, whatever we are discussing admin and development, it is common for all the clouds. But there are some tools which are specific to particular cloud so that I will be starting. And when that bootcamp related to that particular topic will be starting. So in that case, what I will do like three sessions I will keep for this bootcamp and three sessions I will be having for that particular topic. Okay, so that you can understand things parallely. Okay, so let's jump to understand what is at the rate test setup and apex test class. So first I will be discussing it theoretically and then I will be explaining how we can implement at the rate test setup in the apex test class, right? So let me just see if I missed any question in the beginning phase. Okay, so Praveen is asking about like how we can fill the exam form and schedule exam. Okay, so web assessor. So Praveen at the end of the session when I complete everything. So just remind me, I will be explaining you in the session itself. Okay, so if you want to learn collection, so you can go through the session tracker and the beginning videos like if I say the numbering will be from 32, 33, 34, 35 session number 32 to 34, you will find three sessions based on list set and map. So those are related to collection you can go through with that. So Pooja is asking, do we need to learn visual force as I heard that it is now not in use? Yeah, so we rarely use visual force, but to give you some idea because lots of folks were asking, can you have basic sessions on visual force? So that's why I added one week for that. Yes, that I will be doing in night. So maybe nine to 10 slot I will pick for that purpose so that a working professionals can join because that will be targeting both freshers and working professionals, right? So now moving forward. So to understand at the rate test setup, we just need to go through with all these points first. So in front of you, you can see lots of points are listed. So just go through them one by one so that you can understand actually what at the rate test setup is. So basically at the rate test setup is an annotation, right? So in last session in yesterday's session, what we did in each method in each method, we implemented code to create some data, right? So with the help of at the rate set at the rate test setup, what you can do, you can create your data commonly in one method. And then you can just query that created data in different test methods. So first point says use test setup methods that are annotated with at the rate test setup. So there will be only one method which will be annotated with at the rate test setup. So you can use or you can create that method so that you can create test record once and then access them in every test method in the test class, right? So you need to create that method once and whatever data you will be creating into that method, that data you can access anywhere in the test class in different different methods, right? Then next point says test setup methods can be time saving when you need to create reference or prerequisite data for all test methods. So in your test class, if you have lots of data that you need to create in different different methods and you are creating repetitive repetitive data. So if I take you to the org, if I take you to the org, so here you can see in this create opportunity test we created account records. In this method, populate rating insert here also we created these account records and in update also we created these account records. So in each test method, we are trying to create some data, right? So instead of creating them again and again, what we can do we can just implement a setup method that will be annotated using at the rate setup at the rate test setup. And once you need to create the data and that commonly created data you can query into different test methods, right? So last point says if a test class contains a test setup method, the testing framework executes the test setup method first before any test method in the class, right? So these are some points that you need to remember while writing this annotation at the rate test setup, okay? Now if I move forward so two more points are listed here like records that are created in a test setup method are available to all test methods in the test class and are rolled back at the end of the test class execution, right? So whatever data you are creating in the test setup method, the method which is annotated with at the rate test setup, so the data that you create in that method can be called through any other test method and once execution is done, the data or the like whatever process you have done everything will be rolled back, right? So I will be explaining it practically so that you can understand it more clearly. So next point says if a test method changes those records, right? So those record means the records which you have created in the test setup method. So such as record field update or record deletions, those changes are rolled back after each test method finishes execution. The next executing test method gets access to the original unmodified state of those records, right? So these are all the points you will understand when I will be explaining you how we can implement at the rate test setup, right? So now what I'm going to do, I'm going to implement that practically in front of you so that you can understand how actually it is working. So I'm going to create a class and I have a document of Salesforce where some lines of code are available. So I'm going to use this example to demo you how we can use at the rate test setup. So I'm just creating a class named as common test setup, right? So here you can see this class is created. Now what I'm going to do, initial code I'm just copying and I'm pasting and then I will be explaining you, right? And this document is available freely. It is a Salesforce document which is available freely for the reference purpose. So we are understanding through that reference document. So here you can see this is a class common test setup. It is declared as private. Here also we need to use at the rate test at the rate is test is test annotation. Now if we go here so you can see this is another map this is a this is the first method and in this method, we are using at the rate test setup annotation, right? And the name of method is setup method, right? And here data is created. So what we are doing we are creating a list of account and then iterating a loop that will be iterating two times and account records will be created and those account records will be added into the list. And then we are inserting accounts, right? So this way you can create a method where you can commonly create the data. Now I'm going to show you how you can create your test method. So this I'm just copying and then I will be explaining it line by line. Okay, so now in our code you can see first of all we have this part which is a method and it is annotated as at the rate test setup. So this method will be executed first so that data will be created whatever data will be created that data you can query into test method. So here you can see we have a test method. Here we have a test method which is annotated at with the help of at the rate is test annotation and the name of method is test method one method name can be anything right so whatever data we have created here that we can query. So you can see here we provided name as test account and we appended I so I will be zero and then one. So the first account name will be test account zero that is written over here. So what here we are trying to do we are trying to query account ID where name equals to this and limit one so that account record information will be available into this acct then what we are trying to do we are trying to modify phone number of that account record and we are applying update acct so that particular account will be updated right so you can see in this method we have not created the data data is actually created in the above setup method and that we are querying here. Okay so this way the data which you are creating in the setup method so this data you can query in any test method that is implemented here. So next you can see for deletion purpose again we are querying the data and this time we are querying the account where account name is test acct one so that account record information will be available into acct to t2 and then we are deleting it right so this way if you want to perform some operations you can do so this is the first test method that we have implemented and this test method is basically getting or querying the data which is created here. Okay so now if I go here and copy this method as well so this is another method now you will get more clear understanding so if I scroll from the beginning so first of all we have created this setup method which is creating the data then if I scroll down so we have first test method where we have not created data we are just querying the data and we are performing some operations then we have another method this method is test method 2 and here you can see again we are querying the data twice now this time what we are doing we are just checking whether the changes we made in test method one they are rolled back or not right so we are querying test account zero and we are checking the phone number whether it is null or not and here we are querying test account one and we are checking whether this account record is available or not because in above method we updated the phone number from blank to some value and we deleted the second account record so here we are checking whether we will be getting the fresh data that we created above here or we are getting the updated data through any other method so the answer will be when test method one apply any changes into the records so those changes will be rolled back once that test method one execution is completed when you are executing test method two so test method two will be getting the original data that you created in the setup method right so here you can read these comments so it says the changes made by test method one are rolled back and are not visible to this test method get the first account by using a SOQL query and verify that test account created by test setup method is unaltered so it will be equals to null here we updated it with this value but it will be null because in test method two whenever you are querying that account record so its original value will be queried so test method two and test method one both are accessing that data separately which we created with the help of setup method right so this way what you can do you can just create the data commonly and then that data you can query here and you can perform certain operations so I hope this way you understood the adverite test setup feature like how we can create a common method where we can create some data and in different different test methods we can access that data right so with this explanation now if you have any question so you can go ahead and you can ask your queries so that I can answer so Anusha is asking when LWC classes will start so Anusha next month is packed for as in chrono sapix visual force and integration so I think in June lightning web component sessions will be starting so as as I told you like in every session I am explaining everything in detail so that's why things are taking time so in June lightning web component sessions will be starting but prior to that I will be covering the prerequisite that is html css and javascript so vamshi is asking will setup method be private or public if private how we can use it in another method so vamshi if your method is private so private method we can access within the class private method we cannot access outside the class but in within class we can access okay praveen is asking what is exact meaning of rolled back yeah so it is not a silly question it is important because you need to understand the rollback process so rollback means like in this test method one we queried the account record then we updated it through update dml right so once this method is finished so rolled back means that account record will get back to its original state original state was like phone is blank here we didn't provide any value to phone field it is blank but here we are updating but after completion of this method after execution when execution of this method gets completed so phone will become blank automatically so it means it is rolled back rolled back means once the process is completed so record will reach to its original position original values from where execution started so that is basically rolled back so in simple words you can say no change will be there in the record process will get completed but record will be unchanged so that is basically known as rolled back okay praveen is asking start test and stop test so i think those i already explained here so basically so listen it carefully we are now talking about this test dot start test and test dot stop test so basically these two statements control your governor limits so in your test class if you have more than one test methods and for each test method you want separate set of governor limits for operations so all the dml operations you can you can write in between these two statements and in one method you can use this pair once but in different different methods you can use it repeatedly right so right now in this class we have three methods so in each method we have used this pair one time so for each method a separate set of governor limits will be available so naina best practices we will be discussing today so once i finish all the demonstration and explanation then i will be explaining all the best practices so rajiv we can use a certain method one right we can use so if you want to use a certain method one so you can compare two values you can but for demo purpose i just use this example but in each method you can use a certain basis on the requirement so what you can do in this method like when we applied update account so here you can write system dot assert and you can see whether record is updated or not so update dml so you can assume like some trigger is working in background and that trigger is updating account record so you can just apply assert and what you can do so here you can just copy and this way you can write you can write and you can compare it with this this way so this way you can apply it and before that here you need to query the data updated data so first query the updated account record and then you can apply system dot assert equals like this right so this is simple example so what you need to do whatever i demonstrated you yesterday so here you can try and implement this adulate test setup so you can shift this account creation in the adulate test setup and record will be inserted automatically so in case of insert operations you just need to apply these two statements you need to query and apply assert and for update operation you will be querying the data and performing these operations update dml and then you will have so i will also explain this once i explain all your queries so i will be modifying this with the help of this adulate test setup so praveen i already explained this if in a class any method or variable is private so those can be accessible within the class so here you can see these are this is private class so in private class if your method or variable is private so that you can access within the class only in any different class you won't be able to access but in the same class you can here search now you can write normal soql also in between start test and stop test but generally we write dml because through dml your trigger flows and other processes initiates so they make all different different processes and they can have different soqls and dml so generally we write dml in between these soql we already know like it will be executing once only so we just don't prefer soql in between them but dml for sure we write so annusha assert i already explained in yesterday's session so just go through the yesterday's session there you will find here i explained how to write assert so i already explained it in detail so you can just go through yesterday's recording because if i explain every session in other sessions so it will be very lengthy so just i already told you like attend all the sessions go through all the sessions then only you will be able to understand yes Ashok this see all data we will be discussing it is planned for today's session so one by one i will be going to explain everything so someone is asking how to reduce runtime for a particular method so you should be implement you should implement optimized method so number of like loop should be less process should be simple then only you can reduce runtime so Vishal LWC and all the prerequisite will be starting from June 1st week okay now i am moving to modify this class so here what i am going to do i will be creating a setup method so static void setup and here what i'm going to do i'm going to copy and paste it right and i just need to insert the data okay now what i can do i can just comment all these lines these are not required so here you can see i'm just modifying yesterday's test class so this is our setup method where i just created the data account records and i'm inserting then this is first test method here everything is coming because data is already inserted so you just need to apply this soql and you can apply the assert statement then here also you can comment till here and this assert you can apply now here also uh you can comment it add to this you need to query the data so here what you can do you can query the data which we created above so if you write this so all the data that you created above will be queried and will be available into this acclist and then you can iterate that acclist and you can apply update so this way you can see from each method i just commented the data creation and data is created above commonly so you can see how we reduced the length of the test class by creating common data using this annotation right so i hope this way you understood how we can implement setup method so that repetition repetitive code can be reduced so this i already showed you how to reduce runtime so if you reduce the length of the code then your code will execute faster right and someone is asking about test dot is running test so this i will explain but let me complete other topics then i will show you an example of this test dot is running test right so moving ahead so this i already explained you like at the rate test set up now the next topic is how we can implement this test utility or data factory class so basically what we did using this at the rate test setup in in a single class if you are creating repetitive data so in the same class you can create this setup method and the data you can just use in different test methods right so this is the use of this setup method but it is limited to this class only now there may be requirements in future like the data which you are creating that can be required by different different test classes there may be possibilities the data which you are creating that can be required in different test classes so what you can do you need to create a separate class you need to create a separate class where you will be creating the data and that class method you will be calling into the test class right so that is basically known as test utility or data factory class okay so now first of all i am going to implement that for you and then i will show you how we can call those methods here okay so i am just creating a new class so name of that class can be data factory it can be test utility it depends on you so i am naming it as data factory and in this class i am going to implement a method so here we will be implementing method as public because this method we need to call into another class so that's why i'm creating it as public its return type is list of account so it will be returning account list and the name of method is create account record then it will be receiving some parameters like name then integer count like how many records you want to create and boolean is insert like you want to insert the data immediately or not right now here what i need to do i'm just creating list of account now i'm going to implement a loop which will start from one and it will go till count so whatever value of count is here we have a count variable so we are using this count variable here for condition checking so for example if count value is 10 so this loop will be iterating 10 times so 10 records will be created automatically so here we need to write account acc equals to new account then acc dot name equals to name plus i and then acc list dot add acc so this way i'm trying to create a count records and we need to set active as well so acc dot active equals to true now if is insert so here we are providing a privilege like if you are passing like we need to insert the data immediately so here you can write this if condition and you can write insert acc list so if this is insert boolean variable is true then your data will be inserted automatically if it is false so insert won't work and we are just returning a count list right so this way you can create a common method in the data factory class right now what you need to do you need to call this method in your actual test class right you need to call this method in your actual test class so here it is showing some error okay it should be yes not true right so i'm moving here and i'm just deleting this test setup method and here i'm going to call it so here i'm creating list of account acc list equals to new list of account and then acc list equals to data factory dot and from here we need to call this method so i'm just copying it and pasting it here now here i'm just passing the name as test number of record let's say 10 and i'm passing true so what is happening here i'm just calling this create a count record method so here create a count record method is available which is expecting three parameter name count and is insert so for name i'm passing test count as 10 and is insert as true right so here we will receive test here we will receive 10 here we will receive true so the records will be created and true is insert is true so data will be inserted once data is inserted so that account list will be returned and it will be available here so this way you can create a separate class where you can have some data and you can call it like this same you can copy and you can paste it here also as simple as that so we created the data once we created a method where data is creating once and we are calling it again and again now you might be thinking what will happen if i pause if i pass false here what will happen if i pass false here right so if i pass false so this if condition won't be working it is false so insert won't work so what will happen the data which we created here it will be returned as it is but it is not inserted it is not inserted so it will be available here in acc list now for example the common data which we have created so here we just assigned values to these two fields this is common for all but for this specific method we want to set some more field values so what you can do you can iterate it again and you can set the value so let's say industry equals to energy so you just modified it and then you can write insert acc list so this way what is happening this is a common method which will be called through different methods so name and actor will be set for each method but for this method we have separate requirement like we need to set values for some different fields as well so what we did we just passed false from here and the returned values we just iterated and we update we set some values and then we applied insert operation so this way through this third parameter you can just control whether to insert the data here only or to return the list and insert the data here in this test class right so I know it is little bit different for you so just try and implement this scenario in your system because just watching this session and if you don't do practice you won't be able to understand things so just implement and here like you can find crisp videos on all these topics so after watching this session if you want to have a scenario so you can go through iterate test setup annotation for bulk apex test and test utility class for bulk data creation right so these are some scenarios that you can implement at your own now I'm just going to take some questions uh yes Archana if you are updating list of records so you can apply assert for only one random record so that you can validate whether that complete list is like updating or not so Ashok which one which third method you want me to revise so Shiv Shankar we are using name plus i so that i will be changing from 1 2 3 4 5 so name will be updated automatically so here what is happening from here we are passing name as test this test will go to this name so here what we are setting we are writing name plus i so test plus one so test one test two test three test four this way data will be created Archana know we we never combine data factory and test setup method so if you do so what you need to do in test setup if you are calling data factory methods so in test methods you need to apply soql so again there will be lots of headache if you apply soql so instead of calling data factory method in test setup and then uh then write soql so it will be better to call data factory methods directly in the test method yeah so Ashok difference between test setup and test utility so in test setup we are creating common data but that common data you can access in that class only whereas in test utility or data factory in test utility or data factory this is a separate class and if you want to call it so for example i i just want to call it in this class also so you will be able to do so so if you want to create some data here so you can call that data factory method in any other class as well so the difference is test setup method common data is available for only one class one test class but test utility or data factory data is available for multiple classes okay so Jana is asking why we are passing this third parameter so Jana if we pass true from here if we pass true from here it means we don't want to modify this data we we need only name and active field set and we want data to be inserted here only and that inserted data will be returned sometimes what will happen instead of name and active you want some more fields to be like some more fields like in the industry type they should also have some values so but you don't want to modify this code here because it is common for all the methods all the test classes so what you need to do you can pass false from here if you pass false from here so your data won't be inserted here only but it will be returned as is whatever loop you have implemented whatever data you created here it is not inserted but it will be returning and once you receive it here so you can apply one loop and you can add some more fields values and then you can apply insert statement right so we are not updating that common method instead we are calling it at different locations and wherever we need some more fields value to be set so there we can just like pass false and then whatever data is returned through that we can iterate a loop and we can set values and we can apply insert operation I hope this makes sense now yes Chandan that that data is created in test class only so Srivalli is asking data factory class methods are not required to be annotated yeah so if you don't annotate it with at the rate test so let me just check yeah so we don't need to annotate it with at the rate is test because why so because we are calling it from a method which is already annotated with at the rate is test so if you are calling it from here so like it is already part of that process yes Ashok all the records will also be rolled back here in test utility as well and it is not at the rate test utility test utility or data factory is just name of the class so Praveen if you don't mention is insert value so your code won't work if I don't pass any value so it will throw an error because I'm just passing two parameters and here it is expecting three parameter so anyhow you need to pass the value you cannot leave it blank so either true or false you need to pass so next is is it ideal to use dml statement and before update context like create tasks no if you are using before update then don't use dml I think that doesn't make any sense so Jana I already explained this lots of time rolled back means you will be on the like step so for example if you have created a record if you are updating that record and something is breaking so everything is rolled back it means you will come from where you started right so that is basically known as rolled back so you will come back from where you started nothing will be applied because your process is failed in epics it is known but in test class if process is completed then also like data changes will be rolled back okay so this way I hope you understood how we can create test utility and data factory class and one more thing I want to show you like here in this test in this data factory right now I just created one method but if you want to create more data let's say you want to create so here in this method we are creating account sorry now here you want to create contact so you can write create contact record and you can change it like for contact right so this way you can change it for contact so I'm not changing it completely but I think now you can visualize in one test class we can have more than one methods to create different different s object records right so just practice it yourself so that you understand now moving forward we have one more annotation which is known as Adlerate test visible it is quite simple so Adlerate test visible I'm going to show within example so I'm not going to implement it because it is very simple so the idea is yeah so just read this line use the test visible annotation to allow test method to access private or protected members of another class outside the test class right so we discussed like private we can access within the class but now if you want to access private method or private variables outside the class so that is also possible so here you can see classes public but this variable record number and this update record method is declared as private so before that we are using Adlerate test visible right so if you do so so in another class so here it is test visible example here it is test visible example test so in this class if you are using test visible before any method so make sure this is not a test class remember this is not a test class this is a general class if you want to access the data which is available here variable and methods into your test class so here you need to write Adlerate test visible now when you will be implementing your test class using Adlerate is test so here you can call it so this record number this record number is a variable which is available in this test visible example class and here we are calling test visible example dot update record so both are declared above both are declared above so you can see from this class these two entities we are accessing here so remember in any Apex class if you have private entities and those private entities like variables and methods you want to call in your test class so you can use Adlerate test visible so it is kind of an interview question so you just need to be aware with this okay let me see if there are any questions so Ashok we never declare anything so here you can see I never I didn't mention any annotation so data factory is just terminology right you need to call to create the data so name can be anything it is not mandatory to use data factory or test utility it is just generic term you can use any name and through that also you can create okay so moving forward next is run as so someone asked like how to use run as in Apex tests so yesterday I think someone asked so I just have one example for that as well so basically run as we use so that if you want to run particular block of code in context of particular user so right now whatever test classes we are implementing those test classes are running in system admin like administrator context or system context but if you want to run your code any particular line of code bunch of code as another user so what you can do first of all you need to create a user so to create user here we are creating username unique username then we are creating we are querying the profile then we are creating the user record right now once user is created then this way you can write system dot run as what you can do you can write system dot run as and I am passing you here so this code this highlighted code will be running in context to this you user and you user profile name is standard user so this code will be running in standard user context so this way if you want to run a particular code in context to particular user or particular profile so this way you can create that user record with the help of profile and this way you can run that code right so let me take questions now yes Chandan after the session I will be explaining you how you can like register yourself for associate exam okay and Praveen is asking if the class is private then we use as visible as possible no if class is private then it is of no use class should be public okay moving next next we have is test see all data equals to true in apex test right so it is also important and in interview generally this is asked like what is see all data equals to true we use it with at the rate is test annotation so if I explain this to you so here I have one more example so all these links I will be providing in the like exercise sheet so that you can go through so here you can see in the first line we are using at the rate test at the rate is test see all data equals to true so what does it mean so just go through with these statement annotate your test class or test method with at with is test see all data equals to true to open up data access to records in your organization so basically if you want to access the org data then you can use it but as per best practice it is not suggested so you can just use you can just read these statements by annotating your class with at the rate is test see all data true allow test methods to access all records the best practice however is to run apex test with data solo using is test see all data equals to false right so but if you want to access your org data you can use it okay but why we don't use it but because in some of the cases like in your org if you have not if you don't have any data so in that case your test class won't be working so it is all always suggested like to create the data because in some of the cases like for particular objects there may be possibilities you have you have no records in that case record creation is better okay so i will be adding all these links in the session tracker here in today's session so that you can go through whatever i explained now quickly i'm going to explain all the best practices and then i will show you how you can register yourself for web assessor right or maybe like if there will be less time because at 9 p.m we have one more session so maybe after this session i can come live again and if you have any doubt while registering so i can just guide you right so let's see how much time this best practices will take and accordingly i will help you out right so this is very important like apex best practices trigger best practices test class best best practices all these best practices are important to understand right so these are simple statements that you need to go through one by one right so just just read all these statements and i think everybody knows i already explained these while explaining different examples related to apex test so you need to start test class with at the rate is test annotation then start test method with at the rate so class also and test method also with at the rate is test annotation then all the methods of test class must be static and void static because they will be called automatically and they won't be returning anything then you need to name your test class as your original class plus test or if you are using trigger names so trigger name plus test so always append test word at the end of your class so that if you are working as a developer and your test class any other developer is using so they should know through that name like it is a test class then prepare bulk test data which needs to be used for test run so i already told you whenever you write any test class so you just need to implement that test class with bulk data so whatever example i shown you i also created data in bulk so if you create data in bulk so it means like your you are just testing all the processes for single records and bulk records if those processes are working fine for bulk records so it means you have implemented them properly right so moving forward we have more best practices statement so at least 75 percent code coverage should be there because if you don't have that much code coverage so your code won't be deployed to production then calls to system.debug are not counted as part of epics code coverage so in your epics class if you have system.debug so that won't be part of your code coverage then if code used conditional logic so this i think i showed you on monday in monday session i showed you if your code has if else branching so you need to execute each branch so you can have different different methods so that all the process will be covered then make calls to methods using both valid and invalid inputs so this also you need to take care so just just try to implement at least two or three methods so that you can provide some valid or invalid data and in both the ways your epics code should work properly then use the run as method to test application in different user context so this i already showed you like to use this run as method you just need to create the user if you create the user then only you will be able to use this method and write comments stating not only what is supposed to be tested but the assumption tested made about the data and the expected outcome so in your test class there should be lots of comments available because whatever you are assuming other developer doesn't know if you don't write comments so write proper comments so that if you implement something so other developer will be understanding what you want to like explain what you assume your assumption should be available in form of comments right then i think this is last slide for today's session so always write test methods will bulkify data so you can use at the rate test setup method or you can use utility or data vectory class so that you can reuse whatever bulk data you are creating and you can use test dot start test and test dot stop test to make sure that the actual testing of your code happens with the fresh set of governor limits so these methods help you to reset your governor limits just before your actual code of testing gets executed right so for each test method you can use this pair and use assert statement to test whether the actual code is executing correctly and giving the results as expected so this is very much required if you don't write assert you won't be able to validate whether your apex code is working fine or not and always try to test both positive and negative scenarios right so these all are best practices that i have for you and now if you have any question you can ask and i think the problem related to associate exam or like web assessor how to use it properly so i will be scheduling one session just after the cyber security bootcamp so i will come live again for 15-20 minutes and then we'll be separately discussing about that there right so let me jump here and see if you have any question okay so chandan like registering is not the problem okay you are able to register but while giving exam they are not able to log in to launch the exam so i think launch button is available 10 minutes prior so you just need to set proper date and time and then you just need to wait for the launch button so next question is these test classes creates unit test to perform yes so if you run all your test classes together so that is basically known as regression testing so you can do end-to-end test through those test classes like if all the test classes are together working or not so ashok at the rate test setup is different see all data is different so archana as in chronus apex we will be discussing next week so next week when i will be discussing future batch cueable schedulable so i will be explaining apex code as well as its test class so praveen is asking a good question if we have trigger and trigger handler so you just need to test the methods which are available in trigger handler trigger will be covered automatically so basically if you are using see all data equals to true then at the rate test setup annotation is not required because you don't need to create data you are just fetching the org data so both are separate at the rate test setup we use when we need to create the data in the test class and this is test see all data equals to true we use when we need to get the data which is available in the org so praveen run as like i will be sharing the links in the exercise sheet so you can just go and have it from there so let me see if i have links handy yes so i am just pasting them so here in this i am just pasting some links yeah so i am just attaching it here so here i just provided all the links which i demoed you can go through yeah so i will format it later on but links are available so you can just go through test visible annotation you can go through runners and you can go through his test okay so you will be able to understand so ashok we don't need to write see all data equals to false because it is by default okay guys so i think i'm done with the session if you have any more questions so quickly ask because i need to take a break and then at 9 p.m we have one more boot camp so if you have any genuine question you can ask otherwise you can also have a break if you want to attend upcoming session and thank you for attending this session so i'm just standing i can i can see there is no question i think today's session was fruitful lots of questions were there and i hope you understood everything whatever i demonstrated so just do practice and through practice you will be able to understand it more clearly thank you so much guys see you after 20 minutes and another boot camp thank you bye everyone