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
if(app.vlocity_ins__Status__c=='Approved by CMS' & app.RecordTypeId == RT)
sbif(app.vlocity_ins__Status__c=='Approved by CMS' && app.RecordTypeId == RT)
Application__c
, each with a different Account_Id__c, then some of the trigger'd records will never be found inAccount
. 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.