0

On a custom page I use an inputField, to make a picklist editable. To make it required I added a validation rule and linked the error location to the picklist field.

enter image description here

But instead of showing up on the field, it loads a new page to only show the error message.

enter image description here

Update failed. First exception on row 0 with id a0Ad000000W8DDOEA3; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Status must be set!: [] Error is in expression '{!doSave}' in component in page up2go_2f:myPage: Class.MY_PREFIX.MyCtrlExt.doSave: line 25, column 1 An unexpected error has occurred. Your development organization has been notified.

I also set it to "Top of Page", same behaviour. didn't help either.

Page:

<apex:form id="form">
    <apex:pageMessages />

    <apex:pageBlock mode="edit">

        <apex:pageBlockButtons location="top">
            <apex:commandButton value="Save" action="{!doSave}" rerender="form" />

        </apex:pageBlockButtons>

        <apex:pageBlockTable...
        // display all the fields I need & do some more stuff

Controller:

public PageReference doSave() {
    update links;
}

How can I ensure, the message will be shown on the location I selected when creating the validation rule?

9
  • can you please add complete error message?
    – Ratan Paul
    Jul 19, 2016 at 10:34
  • @Ratan pasted it
    – itsmebasti
    Jul 19, 2016 at 10:42
  • not sure if you got the point ;) please double check the question.
    – itsmebasti
    Jul 19, 2016 at 10:59
  • yeah looks like links object status field value is not getting binded. can you pls share the complete code.. ?
    – Ratan Paul
    Jul 19, 2016 at 11:06
  • 1
    if you want to add error on field level then you need to add error like sbject.fieldAPIName.adderror('add error massage '); like this way
    – Ratan Paul
    Jul 19, 2016 at 11:18

1 Answer 1

2

Yes, we can specify where the error message would be displayed. But this applies to standard layouts and not to the custom developed visualforce pages. You need to change your function as to make it work:

public PageReference doSave() {
try{
    update links;
}catch(Exception e){
  ApexPages.addMessages(e);
  }
}

This will redirect validation messages to visualforce page. The errors would be displayed at the location of <apex:pagemessages /> tag

You must log in to answer this question.

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