 Hello, everyone. I am Sanjay Gupta. I welcome you on Sanjay Gupta Tech School. So today, we have day 50. So almost half of the sessions are already completed. And this is new week. And in this week, the topic which I'm going to discuss is how to write Apex test classes, right? So we already gone through how we can implement Apex code, how we can implement Apex trigger. So now we'll see what are Apex classes and why we need to implement these test classes, right? Once again, welcome everybody. So I'm just waiting for more folks to join. And from today, like time is a little bit changed. So we are having this session one hour earlier. So if you have someone to whom you want to talk like you want to notify, so please remind them so that more folks can join. Yeah, it is kind of half century. So I just appreciate you as well, like you are consistent with me, watching all the recordings, attending. Many folks are attending live sessions, doing all the exercises, doing practice. I can see your efforts on Telegram group like you are asking lots of questions and answering them. So that is great and keep up the spirit high. And like this is only three months. Next three months like this development and lightning aura and web component sessions will also be there. So this whole six months program will be completed by the end of June or July. And then I have planned a few more boot camp. So those are related to Salesforce and cybersecurity boot camp we already started. And today we will be having day one of that boot camp at 9am, sorry, 9pm IST, right? So, okay, voice is low. Okay, so I will be a little bit louder. So I was just speaking low. So now I will be louder so that you can listen everything. Okay, so moving to next slide. So those who don't know about me so you can go through with this slide so you will be able to understand what I am doing for the community. And whatever I am doing, it is totally free of cost. And like from like this week and last week, I just shared some Udemy courses links as well. So if you are like liking those courses, you can go and find those links in the Telegram group. Okay, so these are some virtual learning best practices. So I hope everybody is following all these virtual learning best practices. So focus on the sessions properly, take proper notes, write down doubts and ask them. So I can see lots of people are asking doubts and Q&A session. And don't miss any session because everything is connected. So this week also, all the topics are connected, right? So one by one, we'll be covering all the aspects related to test classes. And even if you miss any live sessions, so you can just go and watch the recording anytime. And these recordings are available. And right now I don't have any plan to make these recordings private. So it is open for everyone. Maybe at the end of bootcamp, I will decide to make them private. But as of now, these are public, right? So moving forward, this is the great word consistency and consistency is the key. So right now, there are less opportunities in the market, but this is a trend like when market is low, learn new things and when market is up, you can utilize your new skills so that you can grab the jobs, right? So be consistent, do a proper practice, regular practice. And there are lots of things that you can understand and you can learn in Salesforce ecosystem. So you need to be consistent. And I promise like throughout the year you will be having lots of bootcamps and you will be having lots of learning related to Salesforce ecosystem. Moving forward, here I just placed this QR code because few folks were not able to join the telegram group where discussion happens. So through your mobile phone, you can just scan this QR code and you can directly access that particular group, right? So please share this QR code with as many people as you can. And you can see we are in week number 14, right? So week number 14 is related to Apex test classes and lots of things we will be discussing, whatever your doubts will be, I will be covering them. And then we have Asynchronous Apex. So next week, Apex things will be completed and then we will be having Visualforce and integration. And then next six weeks plan will be for Lightning Aura component and web components, right? So this way, like these weeks are planned. So I am going to give you a future insight as well like what will be happening in every week. So in this bootcamp, everything is planned systematically week by week. We are covering each and every topic and you are getting enough time to practice as well. Right? So follow Sanjay Gupta Tech School on all these platforms and share this information with your senior, junior, whoever is related to tech because there will be lots of bootcamps available in few as well. So if you are connected with this platform, so like free, of course, you will be learning many things live. So all the important links are available in video description. So you can just go and have those and you can see whatever I have planned for upcoming. So as I promised you, cybersecurity bootcamp is for you and it is going to be live from today and I am working for other technologies as well. And soon you will hear from me and I am planning to have C and C++ bootcamp in starting from June for college students because on my channel, lots of content is available related to C and C++ and many folks are struggling like how to start learning coding. So in this summer holidays like June, July, I am planning to have that bootcamp. So if you are relative, junior or your friends, like if they are planning to start their BTEC, if they have completed their 12th and starting their BTEC or they are in BTEC first year or second year, so that C and C++ bootcamp will be helpful for those. So I will be creating a separate telegram group for that and soon I will notify you so that you can spare the word and lots of people can be benefited and I myself will be teaching whole C and C++ totally free of cost and live. And in the way I am teaching Salesforce, I will be teaching that. So please share that word with whole community so that everybody can be benefited. Okay, with this, so now today's topic is Apex test class. So after this five, six minutes talk with you now actually I am coming on onto the topic so that this session will be fruitful for you. So first of all, before writing basic Apex test classes, we need to understand why we need to write Apex test class. Okay, so what we do generally, we implement Apex code to implement a particular business logic. We implement Apex code to perform particular business logic and once that business logic is implemented, so we test that as well. And for testing purpose, we go to the UI, we create some records, we do something and we just check whether that code is working fine or not. Right now, if you don't have any QA resource available with you and as part of practice like as a developer, after writing Apex code, you want to test your code through code. So for that purpose, basically we write Apex test classes. So you don't need to go to the UI and create some records. Instead, you will be implementing test classes where you will be creating some data and basis on that data, you will be testing whether your actual Apex code is working fine or not. Right, so Apex test class is totally dependent on Apex programming that we have learned so far. So if you are good with Apex programming, then you will be good with writing Apex test class as well. And if you are working as a developer, so it is your responsibility if you have implemented any Apex class. So you need to write its test class as well so that you can check the unit testing with the help of code. Okay, so here few points are listed. If you go through with all the points, you will be able to understand the introduction of Apex test class. So basically the Apex testing framework enables you to write and execute tests for your Apex classes and triggers on the Lightning platform. Apex unit tests ensure high quality for Apex code and let you meet requirement for deploying Apex. Deploying means moving your code from one org to another. Right, so Apex code can only be written in a sandbox environment or a developer org. So right now the org which we are using, it is a developer org. But when you work on a real time project, so in companies, they will be having production environment and sandbox is basically copy of the production. So you won't be able to write Apex code directly in the production environment. So that's why we first create its copy, which is known as sandbox. And in the sandbox, we write all the Apex classes and those Apex classes, test classes. And along with Apex and test class together, we deploy the code from sandbox to production. Right, so this way, these terminologies you need to understand. So right now, if you are a fresher, you have not worked with any company, so you are just using developer org. But when you will be working with any organization, so you will find production org and you will be having the copy of that production environment, which is known as sandbox. And there can be multiple sandboxes available. Right, so this is brief introduction about Apex test class. Now further here, two more points are listed, which are also related to Apex test class. So here, first point says Apex code can be deployed to a production org from a sandbox. This I already explained. Also, app developers can distribute Apex code to customers from their developer orgs by uploading packages to the Lightning platform app exchange. So I just want to ask one question from you. Like, do you guys know about app exchange? Can you tell me in the chat, like whether you are familiar with app exchange or not? So meanwhile, you type the answer, I'm just going to explain the next point. So next point says in addition to being critical for quality assurance, Apex unit tests are also requirements for deploying and distributing Apex. Right, so without Apex test classes, you cannot deploy your code from sandbox to production. And you won't be able to distribute your code publicly. Right, so I just want to know about app exchange. Do you know about app exchange, what it is? So if your answer is yes, please write the answer as well. Yeah, so few folks have replied like app exchange is just like Play Store. It is used to download applications. So it is correct. App exchange is a library of pre implemented applications which are related to Salesforce. So in your Salesforce org, if you want to install any application, so you can download that application from app exchange, right? So now if you are creating a package and in that package Apex class is available. So you won't be able to upload that package on app exchange until you write test class. So that's why test class is important if you write Apex class. Right, and app exchange contains both type of applications. It can be paid or it can be free. Right, so I can see lots of people answered and there is one more term which is known as managed and unmanaged packages. So basically, if we talk about managed packages, so managed packages means the code won't be visible to you. And if we talk about unmanaged packages, so in that case, you can control the code, right? And this is the major difference between managed and unmanaged package. And I can see lots of folks replied so you already know about app exchange. So just remember two things now. If you have implemented any Apex class and you are deploying it from sandbox to production, then you need to write test class. And if you have created a package and in that package Apex class is available and you want to deploy that package to app exchange. So again, your Apex code should be having Apex test classes. Right, so in interview if interviewer asked like what is the need of Apex class, so whatever I have explained to you that you can explain to your interviewer as well. Now, what is the benefit of Apex unit test? So it ensures that your Apex class and trigger works as expected, which is the primary requirement. Right, so if your Apex class is having 10 methods. So in your test class, there should be 10 or more methods because in this class we focus on positive and negative test cases as well. Right, we can apply different different test scenarios while writing test classes. So there can be more than 10 methods available if your Apex class is having 10 methods, right? And each test class method will be checking the functionality that you have implemented in the Apex class. Okay, so I don't know why voice is low. Okay, so I will try to speak more louder. So second point says having a suit of regression tests that can be rerun every time classes and triggers are updated to ensure that future updates you make to your app don't break existing functionality. So this is important. So what happens, for example, if you have implemented lots of Apex code, if you have implemented lots of Apex code, so in that case, there will be lots of Apex test classes. And now if you update few Apex classes for some business logic change. So what you can do, you can run all those test classes together. You can run all those test classes together or individually, whatever way you want. And you need to check whether by updating your actual Apex class, whether your test classes are failing or not. If your test class is failing, it means you just need to fix them. And if you fix your test class and then it is running fine, it means your actual Apex code is working fine. Right. So this way, like first you need to write Apex code, then you will be writing test class. And then if you update your Apex code, then you can just run your test class. And if it is failing, you need to fix it so that you can verify whether the code you have implemented in your Apex code that is working fine or not. And meeting the code coverage requirement for deploying Apex to production and distributing Apex to customer via packages. Right. So these are the benefits. If your unit tests are failing, then you won't be able to deploy. So you need to make sure all your test methods are passing and there should be appropriate code coverage. So basically there is a requirement of code coverage that is minimum requirement, which is 75%. Right. So if you have implemented any test class, so minimum 75% code coverage should be there. So in today's session, I will show you like how you can check whether code coverage is more than 75% or not or what percentage of code coverage is. Okay. So there are two more points like high quality apps delivered to the production org which makes production user more productive. If you write your test class because you are testing your code through code and high quality apps delivered to package subscribers which increase your customer's trust. Right. So if your code is implemented properly, it is tested thoroughly, then only you can make sure like on client environments, it won't be breaking. Right. So if your code is working fine, your apps are working fine. No error, no runtime problems are there. So it means your customer will be having trust on you. Right. So that's why we implement Apex unit test. Now code coverage requirement for deployment. This is important. Okay. So before you can deploy your code or package set for the Lightning platform app action. Only 75% of code must be covered by tests and all those tests must pass. Right. So we'll see how tests fail, how they pass and how we can check like what percentage code is covered and what is remaining. So everything I will be showing you but with simple examples and in tomorrow's session I will be taking some complex scenarios. So in addition, each trigger must have some coverage. Even through code coverage is a requirement for deployment. Don't write tests only to meet this requirement. Right. So don't think for deployment purpose only you are writing test classes. You need to keep in mind like you are writing test classes so that you can validate your Apex code appropriately, whether it is working fine or not. And make sure to test the common use cases in your app including positive and negative test cases and bulk and single record processing. This I already told you whenever you do testing, don't test your code for single record. Always test it for bulk record. Right. Because whatever triggers you implement those works with bulk records. Right. So for single record sometime process work and for bulk record it fails. So always try to test bulk data. So this we'll see. So we'll see positive and negative test cases will see bulk and single record processing. Right. So these are some code coverage requirement. Those you just need to have now important to remember. So these are some important points that you can remember. So calls to system.debug are not counted as part of Apex code coverage. They are simply ignored. And generally when we write any Apex class so we use system.debug for testing purpose whether particular variable is having some values or not. So if you implemented your code completely then you can just remove all the system.debugs from your code. So it is part of best practice. Right. Then test methods and test classes are not counted as part of Apex code limit. So we have Apex code limit. So these test classes and methods are not part of that. So no worries about writing long test class with more methods just to make sure that all your code branches are covered. Right. Then classes can be deployed on 0% coverage as well. But that overall coverage of your production org after getting your code deployed should be 75%. Otherwise Salesforce won't let you deploy your code. Okay. So overall org code coverage should be 75%. If we move further so here you can see a few syntaxes are available. So first syntax is like you need to use an annotation which is at the rate test. Right. Here you need to write static void and then method name. And another way is to use this test method keyword. So generally we prefer the first one. We write at the rate test at the rate is test annotation prior to each method. Okay. So this is the complete class how you will be writing your test class. So whenever you write your test class so you will be writing at the rate test in the beginning of the class. Then test class can be private because you won't be accessing its method into any other class. So you can define your test classes private the name of the class you need to provide. Then each test method should be annotated with at the rate is test and then static void my test method. So method name can be anything and it should be static because it will be called automatically. So these are the syntax that you need to follow while writing apex test class. Right. So now I have to give you a demo. So before jumping to demo I can see there are lots of questions available in the chat. So I'm going to see whether any relevant question is available. So I will be asked answering that first and then I will give you a demo like how we can implement simple test classes. Okay. So so this is related to apex trigger but right now I'm starting as new but tomorrow session will link this apex test with apex trigger. Okay. Few folks are appreciating my effort. So thank you so much for appreciating my effort. I'm fully dedicated to help the community and for update like today I shared two Udemy coupon codes in the telegram channel. If you missed you can go and grab it is related to PD-1 certification and flow. So just go and grab those. So actually asking interview question and the sandbox type export and a test classes show up 100% code covers still with the 100% code covers in sandbox. It doesn't mean that the production your question isn't complete. How often or so or we will be discussing next month and I will be able to answer but it is less used. So there were no class Thursday. Thursday we launched cybersecurity bootcamp. So there were no class. So Vamshi for clearing associate exam if you have gone through all the admin related videos or sessions right. So if you have that knowledge you will be able to clear directly. It is very simple. So just understand the concept and basis on your knowledge you will be able to clear the exam. Okay. So I don't see much question. So here yeah here we have few questions. So for every class we need 75% or can we make number of classes as bunch and make them code cover. So Nagendra tried to have 75% for each class because what happens when you club. So there may be chances like still after creating a bunch your code covers is less than 75%. So such in if your code is not covered less than like if it is less than 75%. So when you will be deploying your code from one or two another you won't be able to do that. Yes, Janna test classes will be always private. But if you write them public then also it is fine. But as per best practice we need to write it as private. So at the rate is test we need to use whenever we are writing test class. So for test method you need to write at the rate is test and for the class as well. So Srivalli at the rate is test is the annotation and test method is a keyword and there is no difference. Both are same. So Pramod we don't call any method of test class outside. Test classes are executed automatically by Salesforce platform. So you just need to click on the button and whole test class whatever number of methods are there they are executed automatically. So that's why if you make it private so that also doesn't make any sense. Okay so Akshay is asking interview question deployment error in production when sandbox has more than 75% code covers. So sometimes when we deploy and sandbox is having more coverage and still we are not able to deploy. So when we are deploying so there may be chances like after deployment like at the time of deployment a bunch of code is there. Right. It is becoming part of your existing code. Right. That's why if you stuck with 75% only so they may be chances your code coverage is not appropriate at the time of deployment. So try to keep your code coverage 90% 85 to 90% so that whenever you are deploying and like deploying to production and due to some reason it is reduced. So it will be balanced out. Yes, Rajiv. So if we use test dot start test and test dot stop test then governor limits are like not counted or I will be explaining this concept tomorrow because today in today's session the examples which I am demoing in those examples I won't be using this. So I will be explaining it tomorrow. So Nagendra total three sessions I have planned. If you have that session tracker you can go through and check. Yes. Soon as we can have inner class inside the test class but I don't think that is of more use. Okay. So now I am jumping to the implementation part. So I will be demoing you a simple example where I will be first implementing apex class and then I will show you how you can implement its test class. Right. Okay. So I am taking help from trailhead. So one trailhead example I will be explaining to you. Right. So here I am just creating a class named as temperature converter. And in this class I just need to implement the code. Right. So I am just copying the code and pasting it for you. So this example I am taking as a reference from trailhead and this is basically simple apex class and this apex class is having a method for nahi to Celsius. So here we are receiving a parameter of type decimal. Then here some calculation is available and this calculation is basically converting this for nahi into centigrade or sorry Celsius. Right. So with this formula result will be available into the CS variable and that CS dot set scale will be setting like after decimal point after decimal point there will be only two digits. So this is the purpose we are using this set scale and it will be returning the value return type is decimal. So this is our apex class. Right. Now if you want to implement its test class so how you will be doing that. So just click on file and new and then select apex class. So generally as part of best practice if you have your class name as temperature converter so test class name we generally write like this temperature converter test. Right. So that we can identify both the classes. Okay. Now if you want to implement a method here. So first of all what you need to do you need to write at the rate is test before the class so that this test class this class will become the test class. Okay. And here this method is also having this at the rate is test annotation method name is test warm temperature. Then here what we are doing we are calling the method for nahi to Celsius and this method you can see it is defined here. Okay. So in this test method we are calling this method and we are passing 70 as a parameter and the result of this 70 will be stored in this Celsius variable. Right. So I hope this statement you are getting it is simply calling the method of apex class that we are going to test. Okay. So here like I'm just going to call this method and whatever result will be that result will be available in this Celsius. Okay. So we are passing 70 as 48 and the result Celsius will be available in the Celsius variable. Right. Now here we have a method assert equals. So what we need to do we need to check whether the Celsius is having the value equals to 21.11. So we already know if we try to convert 70 into Celsius so it's equivalent will be 21.11. So we are trying to compare like the code which we have called that code is giving the same value or not if it is giving the same value. So this assert equals method will pass. It won't be giving any error. But if both the values are not matching then it will be giving you an error. Right. So I'm going to save it first and then I'm going to show you how we can run it. So first of all what what you need to see. So this is our apex class. And here you can see it right inside in apex class right inside we have this go to button but we don't have any run test button. Okay. I'm talking about this apex class. Now if I go to apex test class. So as we wrote at the rate is test here. So in this you can see here we have a button run test. So because of that at the rate is test because of this at the rate is test this class is converted as a test class. Right. So now what you need to do just open this bar click on this arrow so that this palette will be opened where various tabs are available. And from here we will be using this test tab. So whatever test class you will be executing the results will be available under this test. So I'm just going okay it is so I'm just clicking on run test and you can see a running test as synchronously and here we are seeing the result. Okay. So green tick means your test is passing your test class is working fine failures are zero and total is one total one means one method is there in the test class. If I click on this plus sign again click on this plus sign so the method which is available in the test class will be visible here. Okay. So this way right now whatever value we are receiving here in Celsius it is equals to this. Now for example. From here we are passing 80. Like a Fahrenheit value I'm passing as 80 and I'm still comparing it with 21.11. Right. So now if I save this code and you will see like how your assert will fail. So again I'm clicking on run test and this time you can see it is showing you red cross. It means your test is failing if I expand it and go here and double click so it will give you the error message. So here we have errors and then we have stack trace stack trace will show you the line number where error is occurring. So just double click on this. You will see the error and expected is this but actually it is coming 26.67 because I modified the value knowingly. Right. So this way if assert values are not equal so it will fail. So this means like how your test methods are failing. So if both the values are not matching then your assert equals will fail. So assert equals means it is comparing both the values whether they are equal or not. If they are equal then it will pass. It won't break. If it is unequal then it will break. It will give you an error and your test class won't be working fine. Okay. Now I'm just modifying it so that next time when I will be executing it so it will be running fine. Now I discussed about positive and negative test cases so how we can implement them. So I just implemented a few more lines which are very easy to understand and here you can see. So everything is same here. Everything is same. The difference is we are passing different different values. So if you compare the code if you compare the code so whatever we have written under test warm test sorry test warm temperature. So same code is written here test freezing point same code is written here test boiling point same code is written here test negative temperature. The difference is we are passing different values while calling this method. So you can see in all four methods we are calling this formula to Celsius. But what we are doing we are just passing different different values so that we can test that particular method whether that method will be working fine for all the edge cases. Okay. So we are passing 70 then 32 then 212 and then negative and everywhere you can see we are having assert equals. In this we are having assert equals like this first first value 100 then Celsius sorry then we have third parameter which is text. So whenever this assert equals will be failing so this message will also be displayed along with so basis on this message you can identify which assert is failing. So this is optional parameter that's why it is not available with other assert equals. Okay. So now I'm just saving it so that I can run all four methods. So I'm just expanding and clicking on run test and here you can see a total four methods are executed. So this time total is four because four methods are there if we expand. So here we can see total number of methods are four. Right. So four methods are available here and every method is passing. Now how to check code coverage. So if you want to check code coverage you need to come here on the actual test actual apex class for which you have written the test class and then click on this arrow sign and here you will see the code coverage. So individual method coverage is there and overall coverage is also there. So this way you can just validate the code coverage. So with this demo I hope you understood the basic of writing test class. So you need to write test class like this. So naming convention at the rate test test you need to use with a class and every method then how to run. So here we have a button run test then how we can verify whether it is passing failing how to see the error messages. Right. Then how to see the code coverage. So I hope with this you are able to understand this example. Now moving forward I'm going to take few questions. Yeah. So Nagendra you can go ahead and ask the question. Yes. Promote it is mandatory. If you don't use this at the rate is this annotation that method won't be working automatically. It will be skipped. So asset this coupon code is available in the telegram channel where you are not able to send the messages. So in that telegram channel that code is available. So Nagendra deployment we'll see after the development phase. So right now I won't be able to explain that. So Sachin is asking what is the difference between assert and assert equals. Okay. Good question. So if I come here and let's say if I try to write system dot assert. So here you can see lots of methods are available. Let me just write it again. So if we write assert so here you can see assert method is available. So assert basically requires Boolean condition. So in assert you just need to pass true or false. So if you're passing some value and that is true. So your assert will pass if the result of that Boolean condition is false. So your assert will fail and assert equals will be comparing both the values expected and actual. So this is the syntax. So we have assert then assert equals and assert not equals right. So I hope with this you are able to understand the difference. So a set of test methods are not mentioned public because you can see the classes private. Oh, here it is public. So you can just write it private. So we are just executing these on click of this button. We don't need to call these methods into other apex classes or trigger anywhere. They are just available inside this class. So class you can make private and no need to write public before the static. Right. So I hope this answer is sufficient for your question. So Jenna, I think I already showed you how to check code coverage. So I think you are good with that. So Yaram is asking why 70 is correct because if we pass 70 as Fahrenheit. So it Celsius is equals to 21.11. So expected we mentioned here and actual will be available under this variable. If both are same, then it will work fine. Right. So guys, this value you need to provide yourself you need to provide like what you want as a result. So that you need to write here manually and then it will be compared and how to write test classes for trigger that I will be explaining tomorrow. It will be a little bit different because they are we will be working with S object. So we need to query some data. We won't be writing the data directly. Instead, we will be querying that from S object. So that I will be explaining tomorrow. But right now you just need to understand the basics of apex test class. So for one class, we generally write one test class. So her she's asking what about governor limit so governor limit I will be discussing about it tomorrow. So the governor limit concept is still available with your test class. And that is same. Whatever governor limits we have for apex class same governor limits are available for test classes because test classes are also running your apex methods. Okay. But how to control governor limits little bit that I will be explaining tomorrow. Again, there's no test classes for web services. We will be covering in the integration part. So in integration when you will be writing the code, so we'll be covering its test class as well. So Ashok difference between positive and negative case means like here we are testing the code in different ways like we are passing 7032 different different values. So if you test your code with different values, so it is generally called positive and negative testing. So positive means you are passing appropriate data and negative means you are passing inappropriate data in both the cases it should work fine. Right. So she will is asking about trace flag. So I generally didn't use this much. So right now I don't have much information about this. So we'll see and let you know. Yes. So test classes is for testing the method inside the apex class. Exactly. And make sure whether your business logic is implemented correctly or not. Yes, we need to write at the rate is test in front of every method. If you don't write at the rate is test in front of particular method so that method won't be executed. Yes, Sunil deployment classes are planned but though those will be available after the development phase. Okay. So I hope this way you understood like how we can implement positive and negative test cases. Now I'm going to show you one more example. So I'm going to create one more apex class and then I will show you its test class. So I'm just creating a class named as task utl. So here you can see this class code is available. So basically the method name is get task priority and it will be receiving the lead state as a string. Then here we are checking whether string is blank or not. If it is blank so it will return to true. If it is not blank it will be checking the length if length is greater than two then also it will be returning null. Okay. So this is the validation for input. So lead state should not be null and its length should be two character long. Then we have task priority variable and we are comparing it with CA. So if lead state is CA the priority will be high. If it is other than CA so priority will be normal. So this is simple if else condition and basis on this condition task priority will be returned. So we have to return if this condition is true. If this condition is true then null will be returned. And if it is false then either task priority high or task priority normal will be returned. So this is the use case that is available here for which we need to implement the test class. Right. So I hope this way this this code you understood and it is available in trailhead. So that is that I'm using just for reference purpose so that I can I can explain you the simple code. Now what I need to do I just need to implement the test class and the test class which I'm going to implement its name will be task utl test. So I'm creating it and initially I'm just putting one method here. Initially I'm putting only one method here. So you can see what is happening. The class name is task utl test. So I hope now everybody knows the standard how to write name of the Tesla's then at the rate is test then private. Then before method also we are using at the rate is test method neighbors test task priority. Then here we are calling that method and passing and why we are passing and why. So what will happen it will be checked. So and why will come to the lead state. It is not blank. Is it greater than two its length. So length is two characters only. So both the conditions are false so null won't be returned here. Now what will happen this if else will be checked. So lead state whether it is equals to CA or not. No it is not equals to CA because it is having n wire. So what is happening if condition will falls will become false and normal will be assigned to task priority and task priority will be returned and the value will be returned here. As PRI and then we are comparing PRI with normal if both are equal then your test will pass otherwise it will be fail. Right. So now what I need to do again I need to run this so you can see run test button is available. I'm just clicking on it and it is passing. Right. Test method is passing. There is no error now let's come here and see the code coverage. So this is important now. Come here and see the code coverage. Overall code coverage is 75%. So whole code is not covered if I click here. So you will see red and blue lines. So few lines are covered with blue color and few lines are covered with red color. So the lines which are which are highlighted as red color like you can say for those lines code is not covered. There is no scenario where these two lines are used. Right. So only one scenario is covered where normal is assigned to task priority. So it means what we need to do we need to create more methods here. We need to create more methods here so that your whole code can be covered. So now what we need to do here I'm putting two more methods. So in this method we are passing priority as CA. And in third method we are passing priority as sorry we are passing this what it is lead state. So we are passing it as Montana. So here lead state we are passing as CA here we are passing as Montana. So if we pass CA so this this this piece will work. If we pass CA so line number eight will become true and line number nine will be covered. And if we pass Montana so Montana is having seven characters so its length is greater than two. So this condition will become true and this return null will also be covered. So this way like if you have if else conditions in your code. So what you need to do you need to implement separate methods for true and false cases. So this is also known as positive and negative testing. Right. So now I'm just going to save all the code if I click above and click on run test. So here we'll see the code coverage now. So everything is working fine. All three methods are passed. If I come here and click so here you can see individual methods are covering 75 75 37 but all together if I click on it. So code coverage is 100% right. So this way you just need to implement test methods and then you can just see whether your code is covered appropriately or not. Right. So these things which I explained you these are the basics. One more thing that I need to show you that is this menu. This test menu is available here and here few options are available. Right. So if you want to run your test method from here so you can just click on new run. So all the test classes will be available here. If you click on any test class so whatever number of methods are there you can pick. So for example what you need to do you need to pick some methods from one class and some methods from another class. Let's say I'm checking this method and clicking here and from here I'm checking two methods. So from temperature converter I'm taking two methods and from task util test I'm taking one method. So if I want to run these three methods only if I want to run specific methods so this approaches appropriate. So you can just click on run only these three methods will be evaluated. So here you can see if I expand it so for this class it is showing one method for another class it is showing two methods. You can see. I selected particular method from individual class so this way it is working and whatever like method is passing or failing so those results will be available here. So this way this test menu is available then rerun rerun fail test run all so run all will run all the test classes then abort will stop right. So this way you can just try all these options at your own. So this is the unit testing that we can do with the help of test classes. Right. So I just gave you two demonstrations so you can just go through the recording. If you have not implemented them live and then you can just test them. So this is all what I planned for today. It was like basics of Apex test class and you should know how to write test classes and tomorrow the test classes which we will be writing it will be based on S object and trigger. Okay. So whatever trigger code we have implemented so how it executes that I will be explaining you tomorrow. Right. Now I'm just going to see the chat whether there is any further question. Yes. So whenever we can test the private function. Yeah. So if classes private and if you are not writing public with the method so method is automatically private. Yes. Promote you can add admin project if you have done enough practice. Thank you Sunil for appreciating. So if I want to add test method for is blank what to write. So if you want to test is blank so what you can do just pass blank value pass nothing this way you can pass. So is blank will be tested. Right. So if you don't pass any value it means it is blank. So just any saying something so which I don't relate. Yeah. Can you please explain why you are saying this statement because the sales force is not related to beta it is related to professional jobs in beta no one knows sales force. So Jenna is asking by the help of test class whatever code we test is that called yes. The single single method which we are implementing so through these methods we are doing unit testing. So this method this apex method which we implemented so this method will be executed here with these methods. So we are doing unit testing small small piece we are testing. So Vamshi is asking when to use try catch and when to use so Vamshi basically assert equal we will be using in test classes and try catch we will be using in the apex class. Okay so in apex class whenever there is any chance of runtime error so in that case we basically use try catch so that we can handle the runtime error and here assert equals we are using to compare two values whether the result which is generating it is expected what we are expecting or not so for that purpose. Thank you Nasser for appreciating my efforts so how to test future methods so future method we will be learning next week so next week I will explain you like how you can implement future methods and its test class. So I think Jess Annie is my ex student maybe so he is just writing my dialogue because I used to tell this in engineering college like do your own practice don't rely whatever we are learning so if you don't do practice you won't be able to complete so now I can recall so practice is important because whatever I am teaching if you are not practicing that then these sessions doesn't make any sense right so Vamshi is asking how to test private methods so I am not getting this why you will be testing private methods so in apex class basically we implement public methods in apex test class we write private method and in test class if you are writing method like without public keywords so it is private by default so you just need to click on run test so all the methods are automated automatically we never write private here here we always write public because these methods this is your apex class and these methods we need to call outside this class so that's why these are public so when I know if your method is private you cannot call that outside the class. Yes Vamshi so for scenarios where in apex class if we have any try catch implemented plan and test method we need to implement that so how to test web services so this will be covered in the integration part so Srivalli we generally don't implement apex class as private if you implement apex class as private so how you will be running that class private class is of no use ok so thank you Manoj thank you Pramod ok so if you have any more question you can ask otherwise you can leave because at 9pm we are having one more session which is related to cyber security so I would ask everybody to join that session not for getting the job but to understand what cyber security is because in the world very few people know about cyber security so this is a free platform where Sumit will be sharing his knowledge and like if you are busy and you don't know so you can watch the recording as well so like I'm just going to end this session here only because there are no more question and practice this test class and just listen that session it will be fruitful by the end of those 6-7 weeks you will be having real good understanding of cyber security so in discussions whenever like you are talking with a group and if you know much about cyber security so you can just lead that conversation right so having the knowledge doesn't like give you any shame if you have knowledge so always you will be like be on top of the group you will be having enough knowledge so you can talk about that so when those sessions are available freely and we plan to have only 3 sessions every week so I think everybody can go and attend and in sales force also cyber security is a role so don't think cyber security is something else it is also related to sales force and do join and encourage Sumit because for the first time he is doing live session like me I'm also doing these live sessions for the first time so encourage him share the information and learn things okay I can see there are a lot more questions so let me quickly answer yes I will be covering interview question and answer I already shared them but after completion of this bootcamp I will have some mock interview sessions so Vinay if you have a private method in Apex class you won't be able to call it anywhere so yeah JavaScript you can learn before Apex but like in this bootcamp we are about to complete Apex so you can learn after that because JavaScript we will be using in Lightning Aura component and LWC so you can learn it after Apex as well okay so Vamshi just share that video with me I will go through and try to explain that tomorrow Vinay I already replied for your question yeah just any I always remember each and every dialogue of me so I always say like if you rely on me and if you don't rely on yourself then no one can help so this is true with this bootcamp as well if you just attend these live sessions or watch the recording and you don't do practice you won't be able to learn Salesforce yeah so Vamshi test visible I will be discussing later on thank you Asit yes it is compulsory to learn JavaScript for LWC so I will be having few sessions on JavaScript so that I can guide you basics of JavaScript and then only we will be having LWC okay thank you everyone so now I'm just ending this session here only and join the session at 9 p.m. which is related to cybersecurity thank you so much