Can I determine when an Apex class last ran?

I see that this is an old post from 2014. Now we can use EventLogFile object. You could filter on Event Types to retrieve Log Files for Apex executions. We cannot view the EventLogFile on the UI. Have to use Workbench or Heroku App to view and download the files. The below trailhead gives you details on the options to download files https://trailhead.salesforce.com/content/learn/modules/event_monitoring/event_monitoring_download


There is no log maintained by Salesforce around apex execution by default. If you wanted to find out this information in the future I would suggest building something in your system which tracks such information. Which should be quite straight forward. Here are the steps.

  1. Create a custom object to log this information, it could have fields such as : apex class name, running user etc.

  2. Create a utility class / method which makes an entry into this custom object : //Sudo code Public static LogClassExecute(string ClassName, string UserID) { customobject_c newEntry = new customobject_c; newEntry.className = ClassName; // and so on... }

  3. In all the classes you want to log ... Include the call to utility class as the first line in the constructor. (About this point, there is a better way to do this ... Which is use an abstract class design pattern. Which all the apex classes inherit from)

Tags:

Apex