How to display the custom error message in visualforce page (here iam using the custom object&fields, when i wont enter data and click save that time it show standard errors.but we want to create my own custom error messages.what can i do for this?. please give any example related that one.
Use Try - Catch in your controller and create a message in catch block and add to the page. You will also need to have the <apex:pageMessages> component on your page to display the custom messages you create.
ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'Error: Please enter search criteria.'); ApexPages.addMessage(myMsg);
eg. try{ //your code goes here } catch (Exception e){ ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR, 'Error: Please enter search criteria.'); ApexPages.addMessage(myMsg); }
If this is resolved, please do mark the question as Resolved and the most appropriate/helpful answer as the best answer :). If none of the answers helped you significantly, please post the solution. You may also mark your solution as the best answer.
Error: Please enter search criteria. This is the error message that you will see on your VF page with Salesforce styling instead of the actual Exception message (that you caught).
ApexPages.Severity.ERROR. This enum will show it either as a Warning, Info or Error.
catch (Exception e){ ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR, 'Error: Please enter search criteria.'); ApexPages.addMessage(myMsg); }
If you do not want to create a message in the Controller, you may also use <apex:pageMessage> on the Page and define the message their itself. You may use a variable to decide whether this message is rendered or not.
Hi nishad basha 7, We have one alternate. Steps Step 1: In vf page,First use required = false for that required field so that custom error messages will be displayed. Step 2: Use sample code below to make that field required <apex:outputPanel layout="block" style="float: left"> <apex:outputPanel > <div class="requiredInput"><div class="requiredBlock"/> <apex:inputField value="{!acc.name}" required="false" /> </div> </apex:outputPanel> </apex:outputPanel>
How to display the custom error message in visualforce page (here iam using the custom object&fields, when i wont enter data and click save that time it show standard errors.but we want to create my own custom error messages.what can i do for this?. please give any example related that one.
Please go through this post.
https://developer.salesforce.com/forums/?id=906F00000008mMjIAI
ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'Error: Please enter search criteria.');
ApexPages.addMessage(myMsg);
eg.
try{
//your code goes here
}
catch (Exception e){
ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR, 'Error: Please enter search criteria.');
ApexPages.addMessage(myMsg);
}
If none of the answers helped you significantly, please post the solution. You may also mark your solution as the best answer.
how to display the custom error message using visualforce? please give me the example of that scenario.
ApexPages.Severity.ERROR. This enum will show it either as a Warning, Info or Error.
catch (Exception e){
ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR, 'Error: Please enter search criteria.');
ApexPages.addMessage(myMsg);
}
If you do not want to create a message in the Controller, you may also use <apex:pageMessage> on the Page and define the message their itself. You may use a variable to decide whether this message is rendered or not.
We have one alternate.
Steps
Step 1: In vf page,First use required = false for that required field so that custom error messages will be displayed.
Step 2: Use sample code below to make that field required
<apex:outputPanel layout="block" style="float: left">
<apex:outputPanel >
<div class="requiredInput"><div class="requiredBlock"/>
<apex:inputField value="{!acc.name}" required="false" />
</div>
</apex:outputPanel>
</apex:outputPanel>
Go through the example in the link below.Hope it helps you.
http://salesforceglobe4u.blogspot.in/2016/08/how-to-override-standard-required-field.html
Let me know if you need any further help...
HI all,
I am getting two exceptions those are one is standard salesforce error.
and the other one ( warning one) is from try/Catch block.
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,ex.getMessage()));
can you suggest me hoe to stop standard message error.
Where you able to override the standard Salesforce Error?
Thanks,
Prudhvi