Scheduled Apex for low-traffic automation: defining an acceptable staleness window and scheduling-user permission boundary
0 reputation · 06 May 2023, 17:03 UTC
0 reputation · 06 May 2023, 17:03 UTC
For a low-traffic Salesforce automation currently relying on an always-on external worker, Scheduled Apex is a documented fit for periodic batch processing. The class would run on a configured schedule rather than continuously polling, which may reduce idle compute costs. However, the cost case is architectural rather than guaranteed, because edition, add-ons, API usage, and storage still determine the final bill.
Two unresolved boundaries complicate the design. First, Scheduled Apex generally executes with the scheduling user's record access, so the class cannot assume administrator sharing or broader visibility than that user's profile and permission sets allow. Second, the business owner has not yet defined the maximum acceptable data-staleness window; if downstream consumers require near-real-time updates, a schedule is the wrong trigger and event-driven automation should be evaluated instead. Queueable Apex is a documented alternative, but it introduces completion monitoring, retry, and idempotency concerns that Scheduled Apex does not.
Low traffic also does not imply low governor-limit usage, and scheduled jobs may run late or overlap under load. Before committing, the scheduling user's permission scope and the proposed staleness window need explicit acceptance.
What is the maximum data-staleness window the business owner will accept for this workload? Does the scheduling user's existing record access cover every object and field the scheduled class must read and write? Should the implementation use Scheduled Apex or Queueable Apex given the need for bounded staleness and minimal operational overhead?
35775 reputation · 06 May 2023, 21:17 UTC
The maximum acceptable data-staleness window is not defined in the request. The business owner must specify it in minutes or hours before any schedule can be accepted or rejected. The scheduling user's record and field access cannot be assumed to cover every object and field the scheduled class must read and write; that coverage must be audited explicitly. For bounded staleness with minimal operational overhead, Scheduled Apex is the better fit. Queueable Apex should be used only when the workload is event-driven or requires chained execution, because it adds completion monitoring, retry handling, and idempotency requirements.
without sharing.If the business owner accepts a minutes- to hours-scale delay, a cron schedule aligned to that window is operationally simpler than Queueable Apex. If downstream consumers require near-real-time updates, Scheduled Apex is the wrong trigger regardless of the scheduling user's permissions.
without sharing solely to close access gaps; adjust the user, profile, or permission sets instead.Run a test job and inspect AsyncApexJob and CronTrigger to confirm execution time, status, and errors. Execute the job under representative load to observe late starts or overlapping runs.
What is the business owner's maximum acceptable staleness window? This detail changes the recommendation because near-real-time requirements rule out Scheduled Apex.
This guidance assumes standard Salesforce Scheduled Apex behavior in a production org. Exact cron timing is approximate and not guaranteed. Edition limits on the number of scheduled jobs may apply and were not verified against the target org.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.