I have a requirement where the user is updating a table and when he/she clicks on the Save button a POST service is called and the data gets saved. The requirement is now enhanced where by the user will get an error message on the front-end if the Save has been unsuccessful. How do I display an error message on the failure of save feature?


  • are you talking about visualforce or lightning? visualforce can use ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'something went wrong')); method to display the message, lightning, you need to catch and re throw a AuraHandledException('Error message to display in Lightning'); ` – Xi Xiao Jan 17 at 7:49
  • My mistake.. I am using Lightning component.. Can you please explain a bit more on how to use the line "AuraHandledException('Error message to display in Lightning'".. I am newbie into SFDC... – Rivu Indra Jan 17 at 7:59

For Lightning component, we are supposed to throw AuraHandledException to client with meaningful message. A quick example below:

  // run your POST call here
} catch (Exception e)
  // call out function failed;
  throw new AuraHandledException('This is the message I want client browser to see');

For detailed explanation read here: https://developer.salesforce.com/blogs/2017/09/error-handling-best-practices-lightning-apex.html

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.