1
trigger UpdateApplicationStatusToEnrolled on vlocity_ins__Application__c (before update ) {
    Map <string,List<vlocity_ins__Application__c>> strMap = new Map <string,List<vlocity_ins__Application__c>>();
    set<id> appaccid = new set<id>();
    ID RT = [Select Id From RecordType Where DeveloperName = 'Medicare_Advantage'].Id;

    for(vlocity_ins__Application__c app :trigger.new)

    {

        if(app.vlocity_ins__Status__c=='Approved by CMS' & app.RecordTypeId == RT)
        {


            List<vlocity_ins__Application__c> appList = strMap.containsKey(app.Account_Id__c) ? strMap.get(app.Account_Id__c) : new List<vlocity_ins__Application__c>();
            appList.add(app);
            strMap.put(app.Account_Id__c, appList);
            system.debug('total record in map'+applist);

        }
    }
    if (strMap != null){
        List<account> accDetails=[select id,(select  id,Policy_Status__c,vlocity_ins__PolicyType__c from vlocity_ins__Policy1__r where 
                                             vlocity_ins__PolicyType__c='MEDADV' and (Policy_Status__c='Active' OR Policy_Status__c='Future' ))from account where id IN: strMap.keySet()  limit 100 ];

        system.debug('total record account'+accDetails);

        for(account  acc : accDetails){


            List<vlocity_ins__Application__c> applicatioList =  strMap.get(acc.id);

            for(vlocity_ins__Application__c application : applicatioList )
            {

                application.vlocity_ins__Status__c = 'Enrolled' ;                
            }
        }

    }  






}

Debug Logs :

07:07:45.36 (143579517)|SYSTEM_METHOD_ENTRY|[31]|System.debug(ANY) 07:07:45.36 (143586250)|USER_DEBUG|[31]|DEBUG|total recordnull 07:07:45.36 (143593327)|SYSTEM_METHOD_EXIT|[31]|System.debug(ANY) 07:07:45.36 (143641112)|HEAP_ALLOCATE|[32]|Bytes:41 07:07:45.36 (143794010)|FATAL_ERROR|System.NullPointerException: Attempt to de-reference a null object Trigger.UpdateApplicationStatusToEnrolled: line 32, column 1 07:07:45.36 (143808046)|FATAL_ERROR|System.NullPointerException: Attempt to de-reference a null object Trigger.UpdateApplicationStatusToEnrolled: line 32, column 1

5
  • 1
    Hi @VijayGanji i will take care if it by next time. thanks for advise. so i am getting error on for(vlocity_ins__Application__c application : applicatioList ) . please find logs as below,
    – alpha
    Jul 11 '19 at 11:06
  • 07:07:45.36 (143579517)|SYSTEM_METHOD_ENTRY|[31]|System.debug(ANY) 07:07:45.36 (143586250)|USER_DEBUG|[31]|DEBUG|total recordnull 07:07:45.36 (143593327)|SYSTEM_METHOD_EXIT|[31]|System.debug(ANY) 07:07:45.36 (143641112)|HEAP_ALLOCATE|[32]|Bytes:41 07:07:45.36 (143794010)|FATAL_ERROR|System.NullPointerException: Attempt to de-reference a null object Trigger.UpdateApplicationStatusToEnrolled: line 32, column 1 07:07:45.36 (143808046)|FATAL_ERROR|System.NullPointerException: Attempt to de-reference a null object Trigger.UpdateApplicationStatusToEnrolled: line 32, column 1
    – alpha
    Jul 11 '19 at 11:11
  • 1
    @alpha Please edit your question to add this information. Comments are not for adding details.
    – David Reed
    Jul 11 '19 at 12:13
  • if(app.vlocity_ins__Status__c=='Approved by CMS' & app.RecordTypeId == RT) sb if(app.vlocity_ins__Status__c=='Approved by CMS' && app.RecordTypeId == RT)
    – cropredy
    Jul 12 '19 at 1:39
  • why do you have limit 100 on the query? If the trigger includes 101+ Application__c, each with a different Account_Id__c, then some of the trigger'd records will never be found in Account. Given that the trigger context is max 200, then you can be sure you will never retrieve more than 200 Accounts and that should be just fine.
    – cropredy
    Jul 12 '19 at 1:55
0

You are getting that error because of this below line

List<vlocity_ins__Application__c> applicatioList =  strMap.get(acc.id);

strMap does not contain a key with the Account Id you are passing, hence it returns null which makes applicatioList variable null. And when you are trying to loop through this variable, you will get the null pointer exception which you are getting.

To fix this issue, you will have to check if the map contains the key, if not then initialize applicatioList to a new list and then loop through it.

Change your below line

List<vlocity_ins__Application__c> applicatioList =  strMap.get(acc.id);

to

List<vlocity_ins__Application__c> applicatioList =  strMap.containsKey(acc.id) ? strMap.get(acc.id) : new List<vlocity_ins__Application__c>();

Note : Ideally your strMap should contain all the Ids as keys, you will have to investigate by debugging the code and identify why is it that map does not contain those values.

0
0

I am not sure why you are getting that but few recommendations.

  1. Remove system.debugs some time printing a list gives you null pointer exception.
  2. strMap is initialized properly so it won't cause you an issue.
  3. Please add if the condition to wrap your code

    if (accDetails <> NULL && accDetails.size()>0){ }

    if (strMap != null && strMap.size() >0){ }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.