You need to sign in to do that
Don't have an account?
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
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.
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