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
Valli KValli K 

how to cover bellow boolean in test class

 public static boolean validatemethod (Id acc,String str,Id rec){
        boolean validatemethod = true;
        List<custom__c> cus = new List<custom__c>();
       
        if(rec==null){
          / 
         cus = [Select id,name from custom__c where account__c =:acc and Product__c =:str];
        }
        else{
         
          
          cus = [Select id,name from custom__c where account__c =:acc and Product__c =: str and id !=:rec];
        }
        if(!cus.isEmpty()){
            return false;
        } 
        return validatemethod;
    }
Valli KValli K
how to cover above boolean method in test class.. else part is not covering code coverage. Please help me here

 
Raj VakatiRaj Vakati
Give me complete code .. 


You need to pass the not null value to the method to   record id parameters for the  validatemethod  methid

validatemethod(Null , null . null) -- > If 
validatemethod ('recordod,'recrdva','recirdid')-- else
 
v varaprasadv varaprasad
Hi Valli,

call the same method in 2times or create 2 test methods:

class.validatemethod(acc,str,rec);
class.validatemethod(acc,str,null);  // pass here null

Hope this helps you!
If my answer helps resolve your query, please mark it as the 'Best Answer' & upvote it to benefit others.

Thanks
Varaprasad
@For Salesforce Project Support: varaprasad4sfdc@gmail.com

Salesforce latest interview questions  :
https://www.youtube.com/channel/UCOcam_Hb4KjeBdYJlJWV_ZA?sub_confirmation=1