+ Start a Discussion

Multiple SOQL query's reach limit

I understand that im running to many querys. Whats the proper way to run querys and not reach the limit? Basically im running 24 querys per user, im doing reports on user data and updateing a object with the calculations. Is there some kind of batch i can send and have it give it back to me. Or do i have to export the results into mysql and run my calcs then send it back? Whats a good way to do something like this with so many querys? Thanks in advance.


If I got it right, you're doing an iteration on a collection of users, and in that iteration you do soql queries ? 


The best practise is to get a list of all user Id's, and then make a single query per object you want to collect and do:


select fields from  object where ParentID, or userId, (whatever the related fieldname) is IN :list_user_ids  limit  X


Subsequently you can process the result and map it to for instance map<id, list<object>> and perform your logic with this.