0

I am working on a requirement and need to get more than 50000 records stored in a set. The scenario is I am having two object with parent to cheild relationship and there are different filter some satisfy on parent and some on child.I need to query parent and get child with parent satisfying the filter condition and then child query to get all satisfying filter condition . In the end I need to remove all the parent record from query one result which doesnt have the child present in query 2 result.

There is coming the 50000 records limit running both the query which is limiting me to download more than sufficient records Is ther any workaround :

Query 1 : results in parent with child with limit 50000
Query 2 : results in child with limit 1200 As child can have maximum 40 child

Want to increase the number of record increase so that to have maximum set id in RecIDFinal

  if (query2.size() > 0) {
                for (childobj childobj: query2) {
                    orRecID.add(childobj.id);
                    RecIDFinal.add(childobj.parentlookup__c); //Adding parent id
                }
            }


            if (query1.size() > 0) {
                for (parentobj parentobj: query1) {
                    RecIDFinal.add(parentobj.id); // Adding id
                    for (childobj childobj: ordRecord.relation__r) {
                        if (!orRecID.contains(childobj.id)) {
                            RecIDRemove.add(ordRecord.id); // removing id if child not matches
                        }

                    }

                }

            }


for (Id objId: RecIDFinal) {
                if (RecIDRemove.contains(objId))
                    RecIDFinal.remove(objId);
            }
3
  • 2
    What are you trying to do with that data? Making the page read-only may work, but obviously not if you need to perform edits. Please spend some time describing your high level objective.
    – Adrian Larson
    Dec 27, 2017 at 5:59
  • I need to get maximum records through query to download and need to do query on the basis of those ids. Page is in read mode only and rest of the part is already been added. Dec 27, 2017 at 6:02
  • 3
    The best practice is to lazyload data as needed. from your description its not clear why you need to load 50000 records at once to UI.
    – RedDevil
    Dec 27, 2017 at 8:37

1 Answer 1

0

Although I'm not completely sure how you are querying this data or why so many records must be returned in the manner in which you stated, one potential option would be to query only one object (either the child or the parent) rather than querying both objects to collect ids from one to use against the other. This approach will allow you follow best practices in terms of lazyloading.

If you must use related data which cannot be directly queried from your "query object", consider adding some formula fields (if querying from the child) or rollup fields (if querying from the parent) in order to filter on criteria regarding the related object using redundant/summarized fields accessible directly by the query object.

After such a refactor, if you are still running into the 50k limit, using only one query in such a manner will make it much easier for you to introduce pagination to your UI, as well.

You must log in to answer this question.

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