You need to sign in to do that
Don't have an account?
LloydSilver
Help fixing bulkification issue
I'm running into a bulk update issue on the trigger below. I thought that I properly structured the apex for bulkification but apparently I didn't and I'm stuck. I'd really appreciate some help. 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; }
Just because it errors with too many SOQL on your code does not mean your code was the issue.
You will need to debug the entire transaction and follow it to see what keeps calling your code inefficiently.
Okay, I didn't actually think about it in those terms.
What is actually initiating whatever is causing the error is a test class created by someone else. Here is the code to that in case something jump out as obviously a problem.