Execute Batch Apex from lightning component with progress bar to show batch job status

4:18 PM


In this post we will see how to execute a batch apex class and add a lightning component to display the progress of the batch job.

The batch job progress status is retrieved from the object AsyncApexJob.

Let's first create a batch job.

Create an apex controller for the lightning component

Create a lightning component for the progress indicator.


5 comments

  1. This is perfect. I was struggling to find a user-friendly way to execute a batch process. I LOVE the progress indicator. Thanks for such a useful blog post!

    ReplyDelete
  2. How can we get response once the job is completed. I am updating a CSV file and would need to show status of each row back once job is completed.

    ReplyDelete
  3. HOw can I get a response (some custom inner class type) after I have the job completed. I am not storing the data in the database.

    ReplyDelete
    Replies
    1. You could make your batch class stateful to build up your return object , then in the finish method trigger a custom platform event , passing your object serialised as string to the platform event .
      Your aura component would need to subscribe to the event and have a handler to use the return - which would be a string that you could parse into a JS object

      Delete
  4. Could you please advise..how this can be done on LWC

    ReplyDelete