2

My users sometimes kick off some long-running background processes (e.g., add 150 records that look like this template, run this batch process, etc.).

Right now, if those processes fail, they are not surfaced well to the users who initiated them. If they succeed, they also never get notified that they are done.

I would love to expose job status and results to the end-user without giving them access to ALL jobs. What is a good approach to this?

Since these tasks are all related to an SObject, I think it makes sense to have an child object that can stand in for that job. That way, on insert, I'd trigger the job and get the Job Id. Then, when the job completes, I can set the status on that child artifact. Does that work? Are there better answers? Surely this is a common problem.

1 Answer 1

1

There are a couple of strategies, but this is mostly a matter of opinion. In the past, I have used the following approaches.

a) I've avoided the need to expose the information by sending emails to relevant users when jobs completed or failed

b) Upon launching a Batch job I've saved the JobId in a CustomSetting/Record that I can then use to retrieve the status (this is useful for batch jobs that run while the user waits)

c) I've saved a list of Batch Jobs (JobIds) in a Custom Setting/Records, and created a page that queries every X minutes and updates the status of all the jobs for the user to see. The user can then simply check this page.

PS: To retrieve status of Batch jobs you'd use the JobID that you obtain and query the ApexAsyncJob object.

2
  • Are batch jobs a good solution for bulk inserts? Nov 9, 2017 at 16:27
  • That is a rather ambiguous question, Charles. They could be, but context is king. Nov 9, 2017 at 16:35

You must log in to answer this question.

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