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
Pritam GajghatePritam Gajghate 

Test class error: System.NullPointerException: Attempt to de-reference a null object

Hi Everyone,

Please help me on fixing this error in my test class.

@istest
    public static void processMap(){
     String s = '{"insurances":[{"insurancepolicyholdercountrycode":"USA","insuranceplanname":"ARROHEALTH","insurancetype":"Other","insurancepolicyholderlastname":"WHITE","insurancephone":"(855) 651-1890","insuredentitytypeid":1,"relationshiptoinsuredid":1,"insuranceid":"22928","casepolicytypename":"Contracts","insurancepolicyholder":"SKYLAR WHITE","relationshiptoinsured":"Self","eligibilitystatus":"Unverified","insurancepolicyholderfirstname":"SKYLAR","insurancepackageid":455702,"insurancepolicyholdersex":"F","insurancepolicyholdercountryiso3166":"US","ircname":"Corporate Billing"}],"count":7}';
      Account a = new Account(Name = 'Test'+  Date.Today());
        insert a;
        
        Map<Account,String> m_aS = new Map<account,String>();
        m_as.put(a,s);
        
        Eligibility.processresponseMap(m_as);
        
    }

Class: 
@TestVisible
    private static Map<Account, List<Insurance_eligibility__c>> processresponseMap(Map<Account, String> m_accountResponse){
        
       Map<Account, List<Insurance_eligibility__c>> m_accountsToInsurances = new Map<Account, List<Insurance_eligibility__c>>();
        
        for(Account a: m_accountResponse.keyset()){
           if(m_accountResponse.get(a) != null){
               string response =  m_accountResponse.get(a);
               EligibilityWrapper ew = new EligibilityWrapper().parse(response);
               //Parse the wrapper/response for this account and generate the eligibility records
               if(ew != null){
                   List<Insurance_eligibility__c>  l_tempIe = Eligibility.createEligibilityRecords(a, ew);
                   Account aUpdated = updateEligibilityOnAccount(a, l_tempIe);
                   m_accountsToInsurances.put(aUpdated,l_tempIe);
               }
            }
        }
        return m_accountsToInsurances;
    }

Appreciate your quick response.
Thank you!
Syed Insha Jawaid 2Syed Insha Jawaid 2
Hi Pritam

Would request you to paste the complete class ,especifically the methods used in this.

Cheers!!!!
Pritam GajghatePritam Gajghate
public class Eligibility {

    /**
     * For each of the account records, new insurance eligibility records
     */
    public static void processEligibility(List<Account> l_account){
        
       Map<Account, String> m_accountResponse = new Map<Account, String>();
       List<Id> l_accountsToClearIEs = new List<Id>();
        
        //Get response for each acc
        
        for(Account a: l_account){
            String response = AthenaPatientCreationAPI.patientEligibilityGet(a);
            m_accountResponse.put(a, response);
            l_accountsToClearIEs.add(a.id);
        }
        
        System.debug('m_accountResponse ' + m_accountResponse);     
        
        //Process the responses and create new eligibilty
         Map<Account, List<Insurance_eligibility__c>> m_accountsToInsurances =Eligibility.processresponseMap(m_accountResponse);
        
        List<Insurance_eligibility__c> l_insuranceEligibility = new List<Insurance_eligibility__c>();
        List<Account> l_accountsToUpdate = new List<Account>();
        for(Account a: m_accountsToInsurances.keyset()){
            l_insuranceEligibility.addAll(m_accountsToInsurances.get(a));
            l_accountsToUpdate.add(a);
        }
        
               try{
            if(l_insuranceEligibility.size()>0){
                insert l_insuranceEligibility;
            }
         }Catch(DMLException Ex){
            System.debug(Ex);
        }
        try{
            if(l_accountsToUpdate.size()>0){
                update l_accountsToUpdate;
            }
         }Catch(DMLException Ex){
            System.debug(Ex);
        }
        
        
       /* List<Id> accountsToSendToIntakeQ = new list<ID>();
        //Accounts to Id
        for(Account a: l_accountsToUpdate){
            accountsToSendToIntakeQ.add(a.id);
        }*/
        //Eligibility.futureCallIntakeQ(accountsToSendToIntakeQ);
    }
    
    /**
     *  Processes the eligibility response for each account
     */ 
    @TestVisible
    private static Map<Account, List<Insurance_eligibility__c>> processresponseMap(Map<Account, String> m_accountResponse){
        
       Map<Account, List<Insurance_eligibility__c>> m_accountsToInsurances = new Map<Account, List<Insurance_eligibility__c>>();
        
        for(Account a: m_accountResponse.keyset()){
           if(m_accountResponse.get(a) != null){
               string response =  m_accountResponse.get(a);
               EligibilityWrapper ew = new EligibilityWrapper().parse(response);
               //Parse the wrapper/response for this account and generate the eligibility records
               if(ew != null){
                   List<Insurance_eligibility__c>  l_tempIe = Eligibility.createEligibilityRecords(a, ew);
                   Account aUpdated = updateEligibilityOnAccount(a, l_tempIe);
                   m_accountsToInsurances.put(aUpdated,l_tempIe);
               }
            }
        }
        return m_accountsToInsurances;
    }
  
Pritam GajghatePritam Gajghate
Hi, Can anyone help me to fix this issue. 
Thank you!