0

From the Visualforce Page, we call a method that inserts a user record and then subsequently calls three future methods to complete the user onboarding process.

  1. insert user record
  2. Call 1st future method to add PermissionSet
  3. Call 2nd future method to do additional work
  4. Call 3rd future method to do some other work

Our requirement is to inform the user after all the future work is completed. If there are any errors reported by the future methods, we need to report accordingly. How do we track the execution status of the future methods and notify users of success/failure? Thanks.

1

Future methods are not appropriate here. You cannot monitor the status of a future job in Apex code, because you don't get their async ID while calling them (so a simple query might find the wrong jobs if multiple users submit in a short period). Also, there's no literal guarantee the future methods would be called in order, and you can't call a future method from a future method. Instead, use a Queueable or Batchable class.

My personal preference would be a batch class, since you'll be able to examine if there were any errors by querying for the job's status. Depending on how you set up the batch process, you might want to notify the member by email, a Platform Event to notify the page, or monitor periodically to check the batch's progress.

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.