You need to sign in to do that
Don't have an account?

Number of SOQL queries: 101 out of 100 ******* CLOSE TO LIMIT
Close is enough to stop my code.
I need help with my Apex code, I am building a list to display to the customer using the only way I know how.
Creating a list of high level data then building the child records within each node; this is working fine with a lesser number of records.
public class API_DocumentRqAndRs { public API_Document__c apiDoc{get; set;} public List<Rq_Argument_Description__c> rqArgList{get; set;} public List<Rs_Argument_Description__c> rsArgList{get; set;} } public List<API_DocumentRqAndRs> getApiDocumentListRqAndRs(){ List<API_DocumentRqAndRs> apiDocRqRsList = new List<API_DocumentRqAndRs>() ;
// Build master list using this list List<API_Document__c> apiList = getApiDocumentList(); API_DocumentRqAndRs apiDocRqRs; for(API_Document__c apiDoc : apiList) { apiDocRqRs = new API_DocumentReqAndResp(); apiDocRqRs.apiDoc = apiDoc;
// Sets the key to query on fApiController.setapiDocId(apiDoc.id);
// This returns a query apiDocRqRs.rqArgList = fApiController.getRqArg();
// This returns a query apiDocRqRs.rsArgList = fApiController.getRsArg(); apiDocRqRsList.add(apiDocReqResp); } return apiDocRqRsList; }
Is there a way to increase my number of queries? I have put much time into getting to this point and need it to work without a major rewrite. Unless someone has a good solution?
Please help! Thanks.
Are there any suggestions? I put time into this solution and out of ideas as to a different solution. The list I am using is straight forward and works nicely except for the limit.
Is this 100 query limit realistic? The user will not reach this limit often and the solution is simple.
I am trying to retreive child records for each document record. What is the difference is I use a loop or some other way? I still must have the same set of records for each document!
Please help with solution.
100 queries is quite realistic. You have to keep in mind Apex code is run in a multitenant environment so the governor limits are there to ensure you don't consume to many resources all at once.
To your question on how to optimize this, we would need a little more detail on the under pinnings of what your code is doing in the loop (e.g. the internal class queries and such). Here is a very basic example of right and wrong:
Wrong:
Right:
Again this is a very basic example of right and wrong. For any of us to help you optimize your code we'll need to see more of the underpinnings.
I query for a list from the documents then using that list I create another list of documents with child records. Right now I cannot hink of another way to do this since I need all the child records for each document. For every document I have to have the related child records. Then I display all this to the user.
The records will have to be queried eventually to match the parent. Why would I need a DB if I was going to read all the child records into a flat file and match the records on my own? Why do I need a DB when I cannot make queries??
Sean's way is the best. Always avoid SOQL in a for loop. Apex has realistic govenor limits, and the DB is there for you to make your proper lists or maps, then go through them as needed. Why would you use up so much resources? Your code would be slow and bloated. Getting the list of Parents then querying the Children is the fastest and easiet way to do it. It shouldn't take you that long to rebuild your class.