Friday 7 September 2012

Display Warning and Error Messages - Visualforce

The <apex:pageMessages> component displays all information, warning or error messages that were generated for all components on the current page. In the previous form, the account name was a required field. To ensure that a standard error message is displayed if someone tries to submit the form without supplying an account name, do the following:
  1. Update your page by inserting the following line after the <apex:pageBlock> tag:
    <apex:pageMessages/>
  2. Now click Save on the form. An error panel will be displayed:
    A Warning for a Missing Field


    Visualforce’s standard controllers contain methods that make it easy to save and update records. By using the <apex:form> and <apex:inputField> components, you can easily bind input fields to new records using the standard controllers. The user interface automatically produces input components that match the type of the field—for example displaying a calendar input for a Data type field. The <apex:pageMessages> component can be used to group and display the information, warning and error messages across all components in the page.

    Learning More

    • You can use the <apex:commandLink> instead of the <apex:commandButton> component within a form to provide a link for form processing.
    • Use the quicksave() method instead of the save() method to insert or update an existing record without redirecting the user to the new record.
    • Use the <apex:pageBlockButtons> component to place command buttons when using the <apex:pageBlock> component.
    • Use the <apex:pageMessage> component (the singular, not the plural) to create custom messages.

No comments:

Post a Comment