function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
rajesh k 10rajesh k 10 

URgent:how to solve Too many SOQL queries: 101 ?

Hi,
         
set<Id> proids=new Set<Id>();
            productList = [select id, name,Quantity__c from Product2 where Every_Bundle__c=TRUE];
            System.debug('&&&&conlist  &&&&&' + OptionalAdOnProductList);
            if (productList.size() > 0) {
                for (Product2 iterateproduct: productList) {
                    allProductsEveryBundleCheckboxcheckedList.add(new WrapperOfProducts(iterateproduct));
                    proids.add(iterateproduct.id);
                }
             List<PricebookEntry> listOfProductRelatedPricebookEntry=new List<PricebookEntry>();
             listOfProductRelatedPricebookEntry=[SELECT Product2Id,Pricebook2Id,UnitPrice FROM PriceBookEntry WHERE Product2Id IN :proids AND CurrencyIsoCode='USD'];
             
             for(PricebookEntry pricBkEntry :listOfProductRelatedPricebookEntry){
             Decimal Listprice=pricBkEntry.UnitPrice;
              mapToProducts.put(pricBkEntry.Product2Id,Listprice);
      			}
            }

Help me...
kaustav goswamikaustav goswami
Can you please check the debug log and see where it is that the query is getting fored repeatedly. From the code snippet that you have pasted it is very difficult to understand as the query may be fired from anywhere within the complete apex transaction.


Thanks,
Kaustav
Waqar Hussain SFWaqar Hussain SF
The error is not in your that code, it is being called somewhere else which hits the limit of soql query which is that you can not query more that 100 in a one context. For more information have a look at this Site.
https://help.salesforce.com/apex/HTViewSolution?urlname=System-LimitException-Too-many-SOQL-queries-101&language=en_US (https://help.salesforce.com/apex/HTViewSolution?urlname=System-LimitException-Too-many-SOQL-queries-101&language=en_US)