You need to sign in to do that
Don't have an account?
GMASJ
Too many SOQL queries: 101 in a method call
I have a method written which is been called inside a visualforce page table if there are less rows there is no issue. when table has more rows it is throwing error as mentioned below
Too many SOQL queries: 101
Error is happening in above code while returning query return NMS.Distributor_Discount__c;
Please suggest me a way how to avoid this error can we use map to over come this if so please suggest me with an example
Thanks
Sudhir
Too many SOQL queries: 101
/* calculate disti discount */ public static Decimal reCalRslrDisc(Decimal listprice,String productcat, Decimal reslrdistdiscount){ Boolean isService = false; system.debug('listprice = ' + listprice); system.debug('productcat = ' + productcat); system.debug('reslrdistdiscount = ' + reslrdistdiscount); if ( reslrdistdiscount == null || reslrdistdiscount < 1 ){ reslrdistdiscount = 0; } if ( productcat=='C' || productcat=='E'|| productcat=='D'|| productcat=='H'|| productcat=='I'|| productcat=='J' ){ isService = true; } if ( isService == true ) { NSP_Margin_Schedule__c NMS = [ Select Distributor_Discount__c From NSP_Margin_Schedule__c where Reseller_Discount__c = :reslrdistdiscount and Service__c = :isService and createddate < 2015-01-17T00:00:00-08:00 ]; return NMS.Distributor_Discount__c; } else { return 0; } }
Error is happening in above code while returning query return NMS.Distributor_Discount__c;
Please suggest me a way how to avoid this error can we use map to over come this if so please suggest me with an example
Thanks
Sudhir
The above class seems to be Alright. But the class might be called many times which has a SOQL executing many times.
Not sure how you are calling the class, but make sure you pass list of values to this class and call class limited times to avoid Governor Limits.
Best Regards,
BALAJI
Thanks
Sudhir
I understand its little confusion to explain over here. If you can provide the method from which this method is being called and from where the parameters are being passed, we can try to help more.
Best Regards,
BALAJI
reCalRslrDisc method is called in below method
Thanks
Sudhir
You should develop thinking that your method could be called in bulk in order to avoid these issues. Let me show you a quick example:
Let me know if this doesn't help
Agustina
The best way is get rid of this problem is
1. Analyze all the queries used in your org.
2. Analyze which queries are used repeatedly.
3. and remove all the unneccesary queries and make use of singleton pattern.
this might help you.
Regards,
Anil
Agreeing with @Agustina.
Instead of passing paramaters separately to the Method and returning a value to be updated in the record from the Wrapper "linew.line"., try passing the list of records to the method and do required validations and updations in the method and return the list of records with updated value.
Best Regards,
BALAJI