7

Can I see the errors or debug messages my @future calls may be generating? How can I see if a @future method was executed at all?

Details: I have a trigger which needs to update some User accounts in addition to doing a lot of things. Unfortunately, updating User objects cannot happen in the trigger and I have to update the users in a @future method.

The problem is that the code to update User objects doesn't work. First, I noticed that I wasn't querying a couple columns I was using, and I fixed that. But this is just me "guessing" what the error could have been. There is probably a better way to discover the error here.

10

Future methods can be debugged in two ways. First, you can open the developer console and perform the action that causes the future method to be called. Second, you can enable debug logs in Setup / Monitoring / Debug Logs.

As for telling if they have executed, check out Setup / Monitoring / Apex Jobs. They will appear here with a status.

3
  • sorry but where do you find that Setup menu ?
    – dde
    Apr 28 '16 at 8:59
  • @dde In Salesforce Classic, Setup is in the upper right corner. With Communities enabled, you have to click on your name in the upper-right corner to find Setup. In Lightning Experience, it's the gear icon in the upper-right corner. From there, you can Quick Search for Apex Jobs or Debug Logs to find the relevant screen. You need to have Manage Users for Debug Logs and Managed Apex Jobs for Apex Jobs.
    – sfdcfox
    Apr 28 '16 at 15:47
  • What's the traced entity? I'm calling mine from a scheduled flow which calls an invocable method which immediately kicks to a future method in the same class. Dec 25 '21 at 19:54
2

The best design to have future method would be to enclose all the required logic in a separate class/method. The future method should just invoke the required logic. So, essentially you can execute your logic from anonymous apex or test classes to validate if its working as expected.

You can monitor debug logs by checking logs via Setup / Monitoring / Apex Jobs.

In addition to that, for critical business cases, you can also create a custom object, to store all such requests and their outcome (success/ error) along with appropriate error message, stacktrace.

1
  • Groovy, yeah this makes sense for unit testing and debug. Still it would be nice to block execution based on a future method outcome much like a Promise or Async/Await would work.
    – Shane K
    Feb 8 '19 at 15:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.