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
SFRichSFRich 

Governor Limit on Upsert

I would like to write an Apex class to read records from a custom staging object (50,000+), upsert them into another custom object, and delete them from the staging object.  Is this possible or will I hit governor limits?  I would like an administrator to be able to kick this process off from a Visual Force page button.  I can't figure out the governor limits.
aalbertaalbert

I think you could accomplish this using a Visualforce page and an Apex controller. The key is to chunk the transactions to avoid hitting a governor limit. Here is how I see the flow:

 

a. User hits button on visualforce page, calls a method in the apex controller

b. That method simply enables a boolean to state that the batch process has started. Return back to the current pageReference.

c.  The boolean set to true in the previous step will enable an ActionPoller component.This is an interval based VF component that will call an apex action method every X seconds (must be greater than 5). This is the key. Each time the Apex method is called, governor limits are enforced. For an apex controller, you can query 10,000 records and insert/update 10,000 records. So make sure this apex method only processes a certain set of datal

d. If the data is done being processed, set a boolean to false to disable the ActionPoller and display a message on the VF page to the user that the processing is done. 

 

 

HarmpieHarmpie
Just wondering about the 10.000. I think a controller can do 100 DML actions. So, assuming 200 objects per DML call, you cou theoretically upsert / delete a total of 20.000 records before hitting the DML limit.