0

My Use Case - After Every 5 minutes i need to get a token from "X-System" and need to store in salesforce. To Achieve this we implemented batch and scheduler.

What Batch and Scheduler Will DO are Below - a) Batch will run in every 5 minutes and make a call to "X-System" and get the token and store the token in Salesforce. Salesforce Custom Application will use that token on various purpose and use cases.

Drawback of this implementation - This Batch Will Call 400 Times Daily and when ever we need to deploy any change to prod, we have to stop the Job.

My Question - Can i changes this implementation to Platform Event and Replace Batch & Scheduler. Please guide.

Regards Nirmallya

5
  • see help.salesforce.com/… - as you can deploy new code w/o having to stop job.
    – cropredy
    Nov 25, 2019 at 5:50
  • Anything on Platform event ? Nov 25, 2019 at 6:19
  • my point is, why change your implementation as you can deploy new apex code to already scheduled jobs in PROD? We're not really here to do design work/architecture work - please see How to Ask
    – cropredy
    Nov 25, 2019 at 6:21
  • I agree with you Sir. My Concern is - Why to run the batch 400 times a day if platform event has some better approach. In Prod, I cannot go ahead and make the changes and allow it for all. its a shared org. Nov 25, 2019 at 6:24
  • Use edit and propose a design in more detail if you want to get Community assistance
    – cropredy
    Nov 25, 2019 at 6:41

1 Answer 1

0

It is hard to be sure this is answering the right question since (as @cropredy said) your question isn't really clear, but on the off-chance I am understanding what you need to do:

  1. Use of a batch to simply execute some logic to get an external value and store it is quite wrong - at the very least, this is going to consume 2 async apex executions per batch execution (start and finish) whereas a scheduled job will only consume the one. This becomes important when you consider that there are limits on async executions per org per day.
  2. Platform Events don't have a built-in delay.
  3. You can consider using scheduled flows, but I suspect your update frequency is too high.

Given these points, it seems you should use (multiple instances of) a scheduled job, and enable deployment of apex code even with pending or executing jobs. The only downside of the latter is that there are edge cases where the scheduled job will fail due to the code getting updated under its feet. Since you will be running every 5 minutes this basically means there could be cases where there is a 10 minute interval instead.

(To run every 5 minutes you probably need 12 instances of your scheduled job.)

You must log in to answer this question.

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