2

I want to customize the error msg which comes like: when i give wrong format of email id to email field so on below the fields error appear Error: Invalid Email Address.

at the same time in debug log this appears :
VF_PAGE_MESSAGE|Invalid Email Address.
VF_PAGE_MESSAGE|Email: Invalid Email Address.

is there a way to get these message in some variable so i can show them in my customize UI ? as well i want to render a particular section of page based on some variable, that variable should know does it have a exception/validation message or not.

2

2 Answers 2

1

You can access all validation messages of the current context by using this code

ApexPages.getMessages()

which return a list of Apex.Message Object. You can use this in your controller to write a debug log or to customize the display of your message without using the default component

<apex:messages />

or

<apex:message />
2
  • Here problem comes, bcz for field validation, controller is not called. So we can't use ApexPages.getMessages().
    – Ankuli
    Commented Oct 27, 2015 at 5:26
  • I thing I'm not getting you. Salesforce validate data only upon an save operation. And this Can not be done in VF without a call to a controller action. If you only want client side validation , I thing you will have to implement it manually because I dont know a way to access salesforce validation messages without a save context. Commented Oct 27, 2015 at 6:13
0

Put an <apex:messages /> tag on your page. You can style it as you want.

https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_messages.htm

5
  • I want error value in some variable, so i can do some rerendering based on that
    – Ankuli
    Commented Oct 26, 2015 at 14:56
  • i want to render a part of html based on error message, you are not getting me.
    – Ankuli
    Commented Oct 26, 2015 at 15:11
  • See the second link above, you will need to find your message and store it in a controller variable, then reference it on the page accordingly.
    – uXuf
    Commented Oct 26, 2015 at 15:13
  • but for field validation error, it doesn't call any method itself, so when i will call those method and store the value in variable.
    – Ankuli
    Commented Oct 26, 2015 at 15:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .