You need to sign in to do that
Don't have an account?
amrit
Immmediate Solution for this:SOQL Exception
Hi,
I'm finding difficulty in solving this issue.When i tried to run atrigger its is showing Too many SOQL queries exception.I know this is because of soql inside for loop..I donot see any queries inside for loop .I cannot find why this error showing if not
trigger CarparkUpdate on Opportunity (after insert, after update) { List<Id> cId = new List<Id>(); List<Id> old_cid = new List<Id> (); List<Car_Park__c> lstCp,lstCp1; Map<Id,Car_Park__c> mapCp = new Map<Id,Car_Park__c> (); Map<Id,Car_Park__c> mapCp1 = new Map<Id,Car_Park__c> (); System.debug('Total Number of SOQL Queries allowed in this apex code context: ' + Limits.getLimitQueries()); System.debug('Total Number of records that can be queried in this apex code context: ' + Limits.getLimitDmlRows()); System.debug('Total Number of DML statements allowed in this apex code context: ' + Limits.getLimitDmlStatements() ); System.debug('Total Number of script statements allowed in this apex code context: ' + Limits.getLimitScriptStatements()); if(Trigger.oldMap != null) { for(Opportunity O: Trigger.old){ old_cid.add(O.Car_Park__c); system.debug('OLdcid'+old_cid); } system.debug('CID111111111111111'+old_cid); List<Car_Park__c> Cp1 =[select id from Car_Park__c where id=: old_cid]; system.debug('1stCp111111111111111'+Cp1.size()); lstCp1 = [select id,Status__c from Car_Park__c where id IN: old_cid];//Too many SOQL queries Exception System.debug('1.Number of Queries used in this apex code so far: ' + Limits.getQueries()); System.debug('2.Number of rows queried in this apex code so far: ' + Limits.getDmlRows()); System.debug('3.Number of script statements used so far : ' + Limits.getDmlStatements()); System.debug('4.Number of Queries used in this apex code so far: ' + Limits.getQueries()); System.debug('5.Number of rows queried in this apex code so far: ' + Limits.getDmlRows()); for(Car_Park__c a : lstCp1) { mapCP1.put(a.Id,a); } //System.debug('#### mapCP1: ' + mapCP1.size()); } for(Opportunity O : Trigger.new) { cId.add(O.Car_Park__c); } lstCp = [select Status__c from Car_Park__c where id IN: cId]; for(Car_Park__c a : lstCp) { mapCP.put(a.Id,a); } for(Opportunity O:trigger.new) { if(O.Car_Park__c != null) { //if(O.Stagename == 'Blocking' || O.Stagename == 'Documentation Handoff') mapCp.get(O.Car_Park__c).Status__c='Blocked'; } } if(Trigger.oldMap != null && mapCp1.size() !=0) { for(Opportunity O: Trigger.old){ if(Trigger.newMap.get(o.Id).Car_Park__c == null) mapCp1.get(O.Car_Park__c).Status__c='Available'; else mapCp1.get(O.Car_Park__c).Status__c = mapCp.get(O.Car_Park__c).Status__c; } } } Thanks
Can anyone please help me to solve this issue asap.
Thanks
Possibly you are hitting the limit due to your test method doing too much, can you post that?
All Answers
Yeah You are correct. There are no any query inside any loop. But there can be possibility to connect with loop where the trigger called. For a example, your trigger is for after update and after insert. Check whether are there any place that you are inserting or updating Oppertunity Object within a loop. If there are, avoid it.
Refer : http://wiki.developerforce.com/page/Apex_Code_Best_Practices
If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.
Thanks for your reply.We are not updating and insert Opportunity object.
You are not updating and insert Opportunity object OR We are not updating and insert Opportunity object within a loop
?????????????
I mean in this trigger we are not inserting or updating opportunity object inside loop
Thanks
Yeah I can see that amrit. I think you didn't get it. I said that Check for all the places where this trigger is firing. And in that places, check for DML (insert, update) inside the loop.
If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.
Im checking in debug log.there is some workflow which is updating some fields in oppportunity. i tried deactivationg those workflows but still showing exception.Is that because of this reason.im not. plz correct me . Can you please tell me where is updating or inserting.When im running test class for this trigger its showing this error.But if im tring to execute the other test class it is displaying error in this trigger.
Thanks
Possibly you are hitting the limit due to your test method doing too much, can you post that?
Hi,
When i tried to run this below test class,its showing this exception.But this test class is not related to that trigger
thanks
well of course that test is related to the trigger. Your trigger is after insert and update on opp, and the test method inserts and updates some opportunities.
I would recommend splitting it into separate test methods and also look into using Test.startTest() to specify when the test starts - this resets the limits for the actual test.