You need to sign in to do that
Don't have an account?
Ravi 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..
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..
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
Thanks for your reply..
Can you provide me the sample code for this. Am littile bit confused here.
Regards,
Sandeep
Can you please provide me access to this code to look into it.
Regards,
Ajay