 Hello, everyone. I am Sanjay Gupta. Welcome to Sanjay Gupta Tech School. This is my website, studysalesforce.com, a video library to learn Salesforce. In this video, I'm going to demonstrate another example related to Apex Test Class. So in this example, I will show you how to cover positive and negative side of the Apex School. So first I'm going to implement Apex class, then I will let you know how to implement its Apex Test class. So name of Apex classes, event utility. So inside this event utility class, I'm going to define a method. So public static string. So this method is type of type string. Sorry, this method is of type static and it will return a string and name of method will be event priority. It will receive a parameter which is event status. Now inside this method, I'm going to create a variable event priority. Now I'm going to check if string dot is blank event status or event status dot length is greater than 2. If both the conditions are, any of the condition is true, like if event status is blank or if its length is greater than 2, then I'm going to return null. Otherwise, I need to check if event status is equals to CA. Then what I'm going to do, I'm going to set event priority equals to high. Else event priority equals to medium. And after this, I'm going to return event priority. So this is my class, Apex class, and that Apex class event utility is having one method that is event priority. And event priority will be returning this event variable based on this condition. So based on event status variable that is a parameter, this method will be working. So here we have if condition which is having true part as well as it is having false case. So now we need to write two different methods or maybe three different methods through which we can cover all the positive or negative aspects. So one aspect is this where event status will be blank or its length will be greater than 2. Second aspect is if it is having value as CA and third aspect is if it's having value other than CA. So now I'm going to save this and I need to implement its test class. So this example is a bit complicated as per the previous demonstration which I showed in my previous video. So this video will give you more insight like how to implement complex code related to test class. So in both the demonstration, I'm not using any S object, but in my next video, you will see S object included as well in this Apex test classes. So one by one, I'm going to implement these things in separate videos so that will help you to understand how basically Apex test works. So as per best practice, the name of test class will be event utility test. Now I need to write at the rate is test then again at the rate is test then private static. So here I need to define some methods. So I'm writing method one. So here you can have any name that suits you. So right now I mentioned method one. So I have to implement three different methods so that I can cover all these things. So I need to call this method as well, event priority. So I'm copying this and I'm going to call it here. So name of classes event utility. This method and here I'm passing. Let's say ind. Right, so it is having three characters. So this will be passed into this event status. So this condition will be tested. And here you can see it is not blank. So the second condition will be tested. It is true because length is greater than two. So it will return null. So here what we need to test, we need to write system dot assert equal. So I need to store the result in this string. So here I'm putting null and here I'm putting areas. I need to put return type as well, public static void. So here I'm renaming it as test. So we are testing event status for length. So test status length. So this way I implemented my test class. So this time what will happen? This part will be covered because we wrote code accordingly. So I'm going to close these things because these are related to previous video. So now I'm going to run this test. So here you can see it is executed and we defined one method. So it is passing. So green is available. It means test passed. And now I'm moving here. Clicking on this. And here you can see if I clicked on all tests. See it carefully. You can see some lines are highlighted as sky blue and some are highlighted as red. So the part which is covered with sky blue color, it is covered. Over coverage is there. But for this red part code coverage is not there because the method is basically implemented to test this scenario. So that's why I told you in the beginning like I will show you how we can cover all the positive and negative test cases. So if you have implemented a method where multiple conditions are available, so you may implement separate methods so that you can test those functionalities. So apart from code coverage or other advantages of implementing test classes to check whether our code is working fine or not. So with this, you can see, like if you're passing more than two character value, so it means the result will be null. And this system dot assert equal is ensuring that RES is equals to null. So if it is equals to null, it means the code which you wrote for that purpose, it is working fine. So this is kind of automation testing, right? So whenever you write apex code, you need to implement its test class as well so that you can accomplish its code coverage as well as you can test the functionality. So both the tasks should be accomplished with the help of test class, right? One more thing I need to show you like here at right-hand side, you can see overall code coverage is available. So this is for org, but if you run any test class for covering particular apex class, so that you can see here. So even utilities covered 50% like four lines out of eight are covered. So from here also you can see the code coverage. Now I'm going to implement one more method so that I can test this high priority or medium priority. So at the rate is test, private, static, void, test, high priority. So here also I need to call this method. So I'm copying these two statements and pasting here. And this time I'm passing CA because if we pass CA, so it is basically for California. So if it fits the value, so even priority will be high. So here I need to put high. So if result is equals to this high, it means that high priority code is working fine. So I'm saving this code. So this time you can see two test methods are available. Both should pass so that we can have the coverage. So I am again clicking on run test. So it executed. So this time total methods are two, both are executed, both are passed. Let's see the code coverage. So if I click on all tests, so now you can see 87% code is covered. Only one line is not covered because it is an else part. So now we need to write third method so that we can pass a value which is equivalent to two character and not equal to CA. So that's why this medium priority will also be covered. So what I'm going to do, I'm going to write one more test method. So private, static, void, test, medium priority. And here I'm going to copy this code, pasting it here. And here I'm going to write medium instead of high. And here I'm writing any, right? So again, I need to run this code, run this test. So I'm clicking on this button here. You can see three tests executed. All are passed. And from here also we can see. So for event utility, you can see code coverage is 100%. All lines are covered. Here also you can see. So now you can see one more thing. Each method is also showing its coverage. Like for through this method, 50% code is covered. And through these 75% code is covered. And in totality through these three methods, 100% code is covered. So this way you can write positive and negative test cases so that you can increase code coverage of your code. So through this, I hope you understood how we can increase the code coverage. Also how we can test the code which we implemented in Apex code, whether it is working fine or not. So this is done with the help of Apex test classes. So I hope this code will, or this video will help you to understand these things. So don't, don't forward to watch my next video, which will include as objects as well. And later on I will, I will demonstrate like how you can write Apex test coverage or Apex test classes while you are implementing triggers. So those all you can find here like study salesforce.com. It is a complete video library to learn Salesforce. So visit this and get expertise in Salesforce. Thank you.