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
Hari.gsHari.gs 

Too many SOQL queries: 101

Hi,

 

The following code throws an error

 

Run Failures:
  SetContactEndDate.mySetContactEndDateTest System.LimitException: Too many SOQL queries: 101

 

list<Account> accs = [SELECT Id, Name, Old_Purchased_Product_Date__c FROM Account];
    String name = accs.size()+ ' *-* ';
    if(null != accs && accs.size() > 0) {
        for(Account acc : accs) {
            count++;
            if(count >= 0 && count <= 50) {
                Id id = acc.Id;
                AggregateResult[] puchasedProd = [select min(Purchase_Date__c)Purchase_Date__c from Purchased_Products_del__c where Account__c=:id];
                if(puchasedProd[0].get('Purchase_Date__c') != '' || puchasedProd[0].get('Purchase_Date__c') != null) {
                    //Account acct = [select Old_Purchased_Product_Date__c from Account where Id=:id];
                    name += acc.Name + ' *-* ';
                    //acc.Old_Purchased_Product_Date__c = (Date)puchasedProd[0].get('Purchase_Date__c');
                    //update acc;                
                }
            }
        }
    }

 

 

Please help me to resolve this......

 

Thanks and Regards,

Hari G S

Rajesh SriramuluRajesh Sriramulu

Hi

 

See this

 

here is the link to salesforce apex limits,
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_gov_limits.htm

post this question in the developer board
http://boards.developerforce.com/sforce/?category.id=developers

 

try to avoid soql query with in for loop or u can modify with Batch apex because it's limit is 200.

 

Regards,

Rajesh.

Andy BoettcherAndy Boettcher

Refer to the documentation on the previous post...

 

Specifically for you, you need to get your SOQL out of the for loop.  Use Maps, Lists, and Sets outside of the loop to gather your records, then you can spin through those within the loop.

 

-Andy