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
RoyalRoyal 

test class code coverage line showd in red color ?

Hi,
I know test class how it will work in salesforce but i dont know why simple single with out any condition also lines are not covered ?
you can see first line is a simple line there is no any condition but it is showing red color why ?
n second if if conditon not sucess else should be execute right, but in red color why ?
how we can do execute this
 
 User-added image
Head In CloudHead In Cloud
Hi Boyapati,
Can you please send the Apex class which you want to covered
Chandra Sekhar CH N VChandra Sekhar CH N V
You need to write two different test methods and insert test records accordingly so that both if & else conditions are coverred.
Temoc MunozTemoc Munoz
We need more information from your side.

Obviously the code in red is not covered and there may be several reasons.

1. Have you checked your debug logs and trace the code execution?
2. Are there any exceptions that are preventing the code from being covered?
3. Try to look for "Attempt to de-reference a null value," "DML Exception,". etc. in your debug logs.
4. If the above code is enclosed in another if-statement that is covered, then you need to meet that criteria.
5. Like Chandra mentioned, you will also need two separate methods to cover both the if and else parts.