function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SergiSergi 

showing error messages with javascript alerts

Hi,

I've a custom VF page with a custom controller too. When the controller catches an exception I put it in an ApexPages.Message, and return null (to the VF page).

 

Is there any way to catch this message with javascript and show an alert with the text? 

asadimasadim

You cannot net Apex exceptions with JavaScript.

 

What you can do is add a public member variable to your controller called, say, errorMsg. Then on your VF page add an outputText with value={!errorMsg}. When your whatever button is pressed have it rerender the outputText. So this way when the button is hit your controller does its job and if it catches an exception it prints it to errorMsg.