Salesforce Asynchronous Apex: How to monitor Queueable Apex Job

 

Looking for Salesforce Training & HandsOn Projects?


Queueable Apex is just another flavor of Async Programming implementation offered by the Salesforce Platform. 

You can refer to my earlier posts on Queueable Job to get a context around this concept:

 In this article, we will explore how to monitor the progress of a Queueable Job using Async Job Id returned. 

 We can start with a simple demo to explain the concept in the following steps:  

 Step-1: The source of data for this demo will “Contacts” Object as shown below. Using the same records that we modified in the last demo. In this demo, we will be running a delete record operation on the Contacts Object & queue it using the Queueable Job Framework



Step-2 & 3: As before we will be using Workbench to build & test SOQL to be used inside the Queueable Job


Step-4 & 5: Create a brand new Apex Class & give it a suitable name



Step-6: “execute” method contains the Delete Statement to delete the selected records from the Contacts Object & writing a debug log for confirmation. Simple & crisp.


Step-7: Now queue this Job using the “System.enqueueJob” statement but this time we will store the Job Id returned by this function in a local variable

Step-8: Writing that local variable in the debug log to refer to it later



After the Job is executed successfully we can check for debug logs to retrieve the value of the Job Id


Step-9: If we look into the debug logs, we should be able to see the Job Id


We can copy the Job Id & keep it handy somewhere safe



Step-10: To track the job we can go to Setup Menu Search. Type “Job” & you will get all possible matches in the list below

Step-11: To get to the Queueable Job, click on the “Apex Jobs” menu option

Step-12: This will present the “Apex Jobs” list view screen, where we can see all types of Apex Jobs with other important data like status & execution timeline & so on


Step-13: Use “Ctrl+F” to run a text search on the browser window, and paste the Job Id that you copied earlier from debug logs. Search it to see if any record on the page matches that string



Step-14: Hopefully this will locate our job with ease. On this screen, you can see a few important pieces of information about this job. Use it wisely & you can do wonders out of it


Step-15: Since the Job was executed successfully all selected records would be deleted from the Contacts Object


Step-16 & 17: We can validate the action using Workbench as well by running the same SOQL statement that we used initially to select the records. This time there should be zero records returned by the SOQL


Hope you enjoyed this article. Please leave your comments to let me know how you like the content and how you find it helpful to learn the topic.

Comments