You need to sign in to do that
Don't have an account?
Lloyd Silver
Please help bulkify this trigger
My incredibly rudimentary SFDC coding skills came up with the trigger below but it's resulting in "too many SOQL queries" errors. I'd appreciate some help bulkifying it.
Thanks.
Thanks.
trigger UpdateAgentCaseCommissionOnCaseUpdate on Insurance_Case__c (after update) { Map<Id, Insurance_Case__c> cases = new Map<Id, Insurance_Case__c>(); Map<Id, Insurance_Case__c> casesstatus = new Map<Id, Insurance_Case__c>(); Agent_Cases_Commissions__c[] accToUpdate = new Agent_Cases_Commissions__c[0]; for(Insurance_Case__c record: Trigger.new){ Insurance_Case__c oldcase = Trigger.oldMap.get(record.Id); if(record.Status__c != oldcase.Status__c && record.Status__c != 'Submitted'){ casesstatus.put(record.Id, record); } else { cases.put(record.Id, record); } } Agent_Cases_Commissions__c[] accstatus = [SELECT Id, Insurance_Case__c, Contract_Type__c FROM Agent_Cases_Commissions__c WHERE Insurance_Case__c IN :casesstatus.keyset() AND Contract_Type__c = 'Agent Contract']; Agent_Cases_Commissions__c[] accnostatus = [SELECT Id, Insurance_Case__c, Contract_Type__c FROM Agent_Cases_Commissions__c WHERE Insurance_Case__c IN :cases.keyset() AND Contract_Type__c = 'Agent Contract']; for(Agent_Cases_Commissions__c acc :accstatus){ acc.Case_Status_Change__c = TRUE; accToUpdate.add(acc); } for(Agent_Cases_Commissions__c acc2 :accnostatus){ accToUpdate.add(acc2); } if(!accToUpdate.isEmpty()) update accToUpdate; }
Lloyd Silver
Still trying to figure this one out if anybody could help. Thanks.