You need to sign in to do that
Don't have an account?

validation rule error msg not getting displayed on VF page
I have a few validation rules defined on custom fields of account object. These fields are getting fetched on a VF page, but the validation rule error messages are not getting displayed on the page. I have added the tag <apex:messages /> in my VF page, still the error msg is not getting displayed.
Kindly advise what i should do so that the validation rule error msg gets displayed on the VF page.
Thanks,
Sandhya
Kindly advise what i should do so that the validation rule error msg gets displayed on the VF page.
Thanks,
Sandhya
Validation rule will fire only when your performing some DML operations. Please check you rerender apex:messages ID.
Do you have controller apex class for vf page?
If yes, on click of button in controller Catch block add ApexPages.addMessages() and rerender apex:messages ID.
method(){
try{
// your logic
}
catch(Exception ex){
ApexPages.addMessages(ex);
return null;
}
}
Thanks,
Veda
Please keep your DML operations in
Please use try using -
You should be able to see the errors.
Note: make sure to rerender "pgMsg".
Thanks,
Srinivas
- Please mark as solution if your problem is resolved.
I have kept my DML operation inside try catch block itself. When i checked in the debug log, the error msg is coming as well.
This is how it is coming in the debug log:
VF_PAGE_MESSAGE| data is invalid
But this is not getting displayed on the VF page.
I tried rerending the apex:pagemessage on button click, still its not working.
My save button calls a function in controller, which inturn calls another function in the class and it is here that the exception is occuring.
Can you please try below steps.
1. Create on string variable in controller to store exception value.
2. set that variable with 'ApexPages.severity.Error,e.getMessage()' value in catch block.
3. In Parent method which is called by directly from page(as you have mentioned above save button is calling one more method where you are getting exception.) after function call check if the string is not blank. If string is not blank, add page message.
Example:
String strException ;
public controller()
{
strException = '';
}
public methodCalledOnClickOfSave()
{
//your logic
callingAnotherMethod();
if(strException.isNotBlank)
{
ApexPages.addMessage(new ApexPages.Message(strException));
}
}
private callingAnotherMethod()
{
try
{
//your logic
}
Catch(Exception e) {
strException = ApexPages.severity.Error,e.getMessage();
}
}
Are you able to solve the issue? Please let me know if you need more information or help on this.
Thanks,
Vedashri
Thanks for your help.
I was not able to find a solution for this, so I had to go with writing custom validation in the controller rather than the standard validation. The function which we were calling in the 'Save' button was overriding the standard validations from being displayed on the page.