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
swain 10swain 10 

How to get code coverage for apex class?

Hi ,
How to get code coverage for this apex class.

public class OV_Flw_Searchcc360 {
    @InvocableMethod(label='Saerch the CC360 ' description='This will get the configuration from Flow and search in cc360')
      public static List<String> searchCC360(List<List<String>> config) {
          try{
          String dispFields=config[0][0];
          String[] fetchFields=config[0][1].split(',');
          String searchFields=config[0][2];
          String objectType=config[0][3];
          List<String> filterFields = searchFields.split(',');
          Map<String, String> fields = new Map<String, String>();
          Map<String, String> sources = new Map<String, String>();       
          sources.put('1',objectType);
          
          for(String f : filterFields ){             
              List<String> fiterMap=f.split('=');
              fields.put(fiterMap[0], fiterMap[1]);
         }
          system.debug('-------objectType-----'+objectType);
          system.debug('-------fields-----'+fields);
          system.debug('-------sources-----'+sources);
          List<sObject> allResult= OV_Searchcc360.isDuplicate(objectType, fields, sources, null);          
         List<Map<String,String>> tblResule = new List<Map<String,String>>();
              
         for(sObject result : allResult){
             Map<String,Object> retObject =  (Map<String, Object>) JSON.deserializeUntyped(JSON.serialize(result));
             Map<String,String> consolidatedMap = new Map<String,String>();
              for(String f : fetchFields ){
                  f=f.trim();
                  consolidatedMap.put(f,(String)retObject.get(f));
              }
              system.debug('------result------'+consolidatedMap);
             tblResule.add(consolidatedMap);             
         }
              
          List<String> finalResult = new List<String>(); 
          for(Map<String,String> fResult : tblResule){
              finalResult.add(JSON.serialize(fResult));
          }
              
          system.debug('------finalResult------'+finalResult);
          system.debug('------result------'+allResult);
          system.debug('------tblResule------'+tblResule);
          List<String> accountNames = new List<String>();
          List<List<String>> stringList = new List<List<String>>();
            stringList.add(finalResult);
           List<String> cc360resultList = new List<String>();
           String cc360result=JSON.serialize(finalResult);
           cc360resultList.add(cc360result);
              
           system.debug('-----------'+cc360result);
          
          if(finalResult.size()==0){
              return null;
          }
        return cc360resultList;
          }catch(Exception ex){
              system.debug('------Error-------'+ex.getLineNumber());
              system.debug('------Error-------'+ex.getMessage());
          }
          return null;
      }
}
Raj VakatiRaj Vakati
Here is the sample code. Update the code as per the comment 
 
@istest
private class OV_Flw_Searchcc360_Test {
    
    static testmethod void testMethod1(){
        Test.startTest();
        
        Account acct = new Account(Name='Test Account');
        insert acct;
        Opportunity opp = new Opportunity(Name=acct.Name + ' Opportunity',
                                          StageName='Prospecting',
                                          CloseDate=System.today().addMonths(1),
                                          AccountId=acct.Id);
        insert opp;
        
        List<List<String>> config = new List<List<String>> ();
        //add config based  to your code 
        OV_Flw_Searchcc360.searchCC360(config);
        
        Test.stopTest();
    }
}