function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
BoxBox 

How would you protect against this gov limit?

Hey guys,

 

I have an interesting question for you and would like to see how you guys would protect against the gov limit as I cannot see how this is possible with the current APEX functionality.

 

Scenario

 

We have a trigger that processes all sub accounts and contacts to a parent account.  This processing is relatively simple and quick and populates information down for partner portals and the like.

 

A new account is created on Salesforce and its bigger than anything that has come before, let’s say there is a parent account, many sub accounts and we have a lot of contact records.  The total sum of records that would be returned from the database is now greater than 1000 which as we all know will blow the gov limit.

 

My Expected solution (doesnt work)

 

I was hoping that I would be able to either:

 

a)      Put the query in a try catch block and nicely handle the error to the User and infrom them that they would have to initiate the population logic from the nice button and get a nice big gov limit

b)      Inspect the limits object while processing but you can never tell if the SOQL is going to push you over i.e.

 

For(Account[] arrAccount : ([select what, I, need from Account]))

{

                // Inspecting limits here is useless as we will raise an error before getting here

                For(Account sAccount : arrAccount)

{

                // and we cant do it here as there is already a big nasty error message on the UI

 

                // TODO : my logic

}

}

 

Let me know what you think,

 

Chris

MVJMVJ
From what I had read in the APEX Guide what you are doing should work. 

Using the For loop with the SOQL querry is not supposed to have the 1000 record limit as it will use the querymore option.

Did you try this and see the failure?

BoxBox

Hey MVJ,

I'm afraid as we are using a trigger each element in the trigger array can only process 1000 db records, so if you have two elements in the update trigger I can process 1000 each. 

So far we haven’t been able to protect the platform from this one and I do fully understand that it will only happen once in a blue moon.  I'm sure someone out there will one day have a huge hierarchy of accounts, contacts and any other object they have used and I want to make sure I don’t get an inbox fully of APEX errors and I can direct the user to either normalise the account structure or push the button to perform the logic for very large structures.