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
Sandeep TechAffinitySandeep TechAffinity 

How to solve Test Class covering issue?

Hi Guys,
I have a Test Class issue can anyone tell me the mistake. I have custom filed "ClinicCode" in the Lead object. I am not passing the code in the test class but the lead is stored under the "leadsWithClinicsList" list. It should be in "leadsWithOutClinicsList"
User-added imageUser-added image
Best Answer chosen by Sandeep TechAffinity
Bryan Leaman 6Bryan Leaman 6
Null and blank are not the same, so if (something!=null || something!='') will always be true.
Try this:
if (!String.isBlank(led.Clinic_Code__c)) leadsWithClinicsList.add(led);
else leadsWithoutClinicsList.add(led);

 

All Answers

Bryan Leaman 6Bryan Leaman 6
Null and blank are not the same, so if (something!=null || something!='') will always be true.
Try this:
if (!String.isBlank(led.Clinic_Code__c)) leadsWithClinicsList.add(led);
else leadsWithoutClinicsList.add(led);

 
This was selected as the best answer
AnkaiahAnkaiah (Salesforce Developers) 
Hi Sandeep,

As Bryan suggested, use !String.isBlank(led.Clinic_Code__c) or led.Clinic_Code__c !=null in the if statement.

And also check the Clinic_Code__c is a formula field or not. If it is a formula then make sure this field should should be empty in your test class.

If this helps, Please mark it as best answer.

Thanks!!

 
mukesh guptamukesh gupta
Hi SAndeep,

First issue was you are using null that's wrong insted of you need to use blank ('') 

Second
You need to Call 2 time same methos -->>>first method will have Clinic_Account__c = '' and Second method should not blank Clinic_Account__c

if you need any assistanse, Please let me know!!

Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh 

 
Sandeep TechAffinitySandeep TechAffinity
Thank you very much guys. Its working