You need to sign in to do that
Don't have an account?
Olver_Bassov
Too many SOQL queries: 101
Hi I'm having the error on my trigger
CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY:CreateOppForNewSubTriggger: System.LimitException: Too many SOQL queries: 101:--
The trigger is
I believe it's something in the for loop but I can't finde where if someone could give me a light it will be much appreciated.
Thanks in advance.
CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY:CreateOppForNewSubTriggger: System.LimitException: Too many SOQL queries: 101:--
The trigger is
trigger ZuoraModoProductUpdate on Zuora__SubscriptionProductCharge__c (before insert, before update) { Set<Id> zsub_ids = new Set<Id>(); for(Zuora__SubscriptionProductCharge__c zspc: trigger.new) { zsub_ids.add(zspc.Zuora__Subscription__c); } List<Zuora__Subscription__c> zsubs = [SELECT Id, Opportunity__c FROM Zuora__Subscription__c WHERE Id IN :zsub_ids]; Map<Id, Zuora__Subscription__c> id_zsubs = new Map<Id, Zuora__Subscription__c>(); Set<Id> opp_ids = new Set<Id>(); for(Zuora__Subscription__c zsub : zsubs) { id_zsubs.put(zsub.Id, zsub); opp_ids.add(zsub.Opportunity__c); } List<Opportunity> opps = [SELECT Id, Modo_Web__c FROM Opportunity WHERE Id IN :opp_ids]; Map<Id, Opportunity> id_opps = new Map<Id, Opportunity>(); for(Opportunity opp : opps) { id_opps.put(opp.Id, opp); } List<Opportunity> update_opps = new List<Opportunity>(); for(Zuora__SubscriptionProductCharge__c zspc: trigger.new) { if(zspc.Zuora__ProductName__c != null && zspc.Zuora__ProductName__c.toLowerCase().contains('modo')) { if(zspc.Zuora__Subscription__c != null) { Zuora__Subscription__c zsub = id_zsubs.get(zspc.Zuora__Subscription__c); if(zsub.Opportunity__c != null) { Opportunity opp = id_opps.get(zsub.Opportunity__c); opp.Modo_Web__c = true; update_opps.add(opp); } } } } update update_opps; }
I believe it's something in the for loop but I can't finde where if someone could give me a light it will be much appreciated.
Thanks in advance.
These are some tips to find how this error is occuring.
Regards,
Rahul
All Answers
Your loops look good. Can you confirm if you have a trigger on Opportunity that updates Zuora__SubscriptionProductCharge__c?
In your case I believe there might also be other triggers on the same object which might be eating up your 100 SOQL limit.
Could you please check if Zuora__SubscriptionProductCharge__c is inserted / updated in loop in CreateOppForNewSubTriggger? It could be a cascading effect of that insert/update?
Regards,
Rahul
your loops look good , so just insert the validation for update i.e. when old value and new value are same your code not run and second thing insert the list size validation before update the list.
Regards
Gyanender Singh
Any idea on how I can fix this without modifying completely ? All suggestions are welcome.
Thank you
These are some tips to find how this error is occuring.
Regards,
Rahul