function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Ravi kumar 292Ravi kumar 292 

How to cover the IF Condition in Test class

Hi All,

I have written a trigger on contact update. In this trigger, wrote some if conditions to check somme conditions as below.. Here am confused that how to cover this if contions in test class. Below is my if conditions.

If(con.Lead__r.Sector__c=='Developer'&& acc.Rating__c!=null){
                flag = true;       
                If(Condition){
                    con.Lead__r.Rate__c = x%;
                }else if(condition){
                    con.Lead__r.Rate__c =y%;
               and so on.......
                }
            }

Please give me some sample code to cover this if condition..

 
Ajay Ghuge 6Ajay Ghuge 6

Hi Ravi,

You just need to create different methods to cover each condition.

1.Method 1 : 
   Assuming the first condition is passed and it enters into first if 
   Inside if is having another condition. Create data matching with this condition

2. Method 2 : 
   Assuming the first condition is passed and it enters into first if 
   Now create data in test method which will not go into the inside if rather it will go the else

Let me know if you need additional information on this.

Regards,
Ajay

Ravi kumar 292Ravi kumar 292
Hi Ajay,
 Thanks for your reply..
Can you provide me the sample code for this. Am littile bit confused here.

Regards,
Sandeep
Ajay Ghuge 6Ajay Ghuge 6
Hi Ravi,

Can you please provide me access to this code to look into it.

Regards,
Ajay
pavan kumar 1864pavan kumar 1864
Hi, Ajay, I have got some confusion while writing the test class could you please help me with that.