How can I notify users of errors that are encountered within a future method?
Outside of a future method I'd usually resort to ApexPages.addMessage(), but this isn't possible without the browser session.
For example, I might need the user to return to a specific contact record to address an invalid field (that was only identified after a callout).
Attribution to: Daniel Ballinger
Possible Suggestion/Solution #1
I found a Discussion Board post by Bob Buzzard that had some suggested solutions.
You can't do this as the @future request is disconnected from any browser session. There's a couple of alternatives I can think of:
Post a chatter message to the user
Send an email to the user
Create a custom object/setting, add the message to that and write a visualforce page for the sidebar that displays the message
Attribution to: Daniel Ballinger
Possible Suggestion/Solution #2
You could have your Visualforce page poll periodically to see if the future action is complete, and then pull any error information out of a database object. This would require some Javascript that will call your controller's status check method after a reasonable amount of time.
Attribution to: Jeremy Nottingham
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/1480