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
Indhurani KanagarajIndhurani Kanagaraj 

Salesforce Test Class Help

Can someone please let me know how to write text class for this? What even i do Code is not getting coved. 

public static void insertInterfaceStagingTable(List<Case> casesList) {
        
        List<Interface_Staging_Table__c> istList = new List<Interface_Staging_Table__c>();
        for(Case tbEC :casesList){
            
            Interface_Staging_Table__c ist = new Interface_Staging_Table__c();
            ist.Interface_Type__c='Decisions Case entitlement';
            ist.Account_ID__c = tbEC.Account.id;
            ist.Account_Type__c = tbEC.Account.Account_Group__c;
            ist.Case_Number__c = tbEC.caseNumber;
            ist.CaseOverrideCostCenter__c = tbEC.Override_Cost_Center__c;
            ist.Installed_Product_ID__c = tbEC.Reference_Installed_Product__R.id;
            if(tbEC.Override_Cost_Center__c==null) {
                String companyCode = tbEC.Account_CompanyCode__c;
                Default_Cost_Center__C cc;
                if(companyCode!=null) {
                   cc = Default_Cost_Center__c.getValues(companyCode);
                }
                
                if(cc!=null && cc.CostCenter__c!=null) {
                    ist.Override_Cost_Center__c = cc.CostCenter__c;//obj.Override_Cost_Center__c
                } else {
                    ist.Override_Cost_Center__c ='';
                     System.debug('No cost center available');
                } 
            } else {
                ist.Override_Cost_Center__c = tbEC.Override_Cost_Center__c;
            }
            
            ist.Product_ID__c = String.valueof(tbEC.SVMXC__Product__c);
            ist.Service_Type__c = tbEC.Service_Type__c;
            ist.Event_Type__c = tbEC.reason;
            istList.add(ist);
        }
        
        List<System_Log__c> systemLogEntriesList;
        Database.UpsertResult[] result;        
        if(systemLogEntriesList==NULL){
            systemLogEntriesList= new List<System_Log__c>();
        }        
        try{
            if(istList <>NULL && !istList.isEmpty() ){
                result= Database.upsert(istList, false);
                System.debug('Interface Staging Records Upserted : ' + result);
            }
            if(result <> NULL){
                for(integer i= 0; i < result.size(); i++){
                    if(!result[i].isSuccess()) { 
                        systemLogEntriesList.add(createSystemLogEntry(istList[i].Id, 'Decisions Entitlement OB Message', 
                        'Insert of Interface Staging Table record :'+ casesList[i].Id +' for Decisions entitlement OB Message callout',  
                        'insertInterfaceStagingTable' ));                                                
                    }
                }
            }
        }catch(exception ex){
            //Just make an entry in the system log
            systemLogEntriesList.add(createSystemLogEntry('', 'Decisions Entitlement OB Message', 
            'DMLException while Insertion of Interface Staging Table record for Decisions entitlement OB Message callout : - ' +  
            ex.getMessage(), 'insertInterfaceStagingTable' ));
            //Added after PIL commenting
        }
        
        try{
            if(systemLogEntriesList <>NULL && !systemLogEntriesList.isEmpty() ){
                Database.insert(systemLogEntriesList, false); //Just for logging - no check if unsuccessful.
            }
        }catch(exception ex){
            System.debug('DMLException while Insertion of Interface Staging Table record for Decisions entitlement OB Message callout :'+ex.getMessage());  
        }        
        
    }