On a project I'm working on I'm starting to get the SOQL maximum query limit. Of course, I can use the debug logs to view all the queries to investigate. But that would be time consuming and difficult. What are some general best practices to reduce the query count? And if that doesn't work for me; what are some other options to solve this (like using @future)?

  • when u mean query limit is it number of rows/character limit ?
    – Rao
    Commented Jan 11, 2013 at 8:18
  • Max no of soql queries I reckon Commented Jan 11, 2013 at 8:19
  • yeah, the maximum of 100 queries per request Commented Jan 11, 2013 at 8:22
  • 1
    We'd need to see your code to see what is going wrong. My guess is, that you're doing soql queries within an iteration, this should be avoided always, have a look at: salesforce.stackexchange.com/questions/5633/… Commented Jan 11, 2013 at 8:35
  • 1
    doing insert or update doesnt count in SOQL Query limit, it is a separate limit (No. of DML Operations). Generally these are the SELECT statements you are writing in your code. if they are in for loops you get this. Try using SET of Ids or where clauses to SELECT records Commented Jan 11, 2013 at 15:04

1 Answer 1


Per your comment on the question about performing insert and update operations in a loop, it appears that reading and implementing SalesForce's "Best Practices" in your Apex DML operations would be the best start.

Apex Code & DML Best Practices

With special attention paid to items 2 and 4. Though the examples are written within triggers, these best practices should be adhered to everywhere in your codebase.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .