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
CliffACliffA 

What's the best way to retrieve/update records in quantities that exceed governors?

I have a custom field on the contact record that needs to be updated once a year to summarize YTD and Prior Year activity.  I can't use the standard SF rollup fields because it is not possible to dynamically specify the "current year" in the calculation.  I also can't hard-code the current year because the field is part of a package and I don't want to force users to install a new package at the start of every year.  Note that a trigger maintains the YTD/Prior Year activity fields on an ongoing basis.  The bulk update is used at the beginning of a new year to essentially move the YTD amount to the Prior Year field and reset the YTD field to 0.

I've thought through/tried a few solutions but none of them are viable/palatable:
  1. Use VisualForce to create a page with a button that would initiate the mass-update via an @future Apex method.  Good in concept but I'll quickly run into governor limits.
  2. Use the VisualForce/button solution and have the user initiate the update multiple times, biting off chunks of the data each submission that will fall under the governor limits.  Not a practical solution from a user interface perspective.
  3. Use an s-control and make multiple API calls that are within the governor limits.  This would work but it feels wrong to rely on the browser to perform a bulk-update
I couldn't find any other posts on this issue but I suspect others have faced this.  Has anyone else come up with a solution to this challenge that they can share?

Thanks...




Drew1815Drew1815
Is this a annual activity by a System Administrator?

If so, you could write the roll-up logic in a Contact trigger or off a custom object depending on the final requirements. And then use the data loader (or any other extract/update) tool to simply "touch" all necessary records - which will cause the "update trigger" to fire. And maybe you have a custom field (boolean) that you set to true to signal that this update operation is your Year-End processing/calculation. Then the trigger checks if that boolean field is set to true and performs the logic. The trigger will handle each BATCH of Contact's being updated by the API (ie data loader) and therefore should not hit the governor limits.

Is that a viable solution?

-Andrew
CliffACliffA
Hi Andrew,
Thanks for the suggestion.  It's an approach that looks like it would work but it's a process that's likely beyond the ability of many of our users.  We're looking for a solution that's so easy to use that there's no excuse for not running it.  Unfortunately, requiring them to use a desktop application as part of the solution would give them an excuse :smileyhappy:

-Cliff


boihueboihue

Hi,

I hope the following suggestion will be helpful.

- I suggest to use the Apex Data Loader to update the modified Contact records.

- Create a trigger that will update your desired fields, in this trigger, add all Contact records to a List of Contact then update the Contact List at once. Please remember that if you upload the Contact in Bulk, the trigger will be fired and execute 200 Contact records at a time.

Regards,

Boi Hue