How to write message class in apex controllers?

Message Class:
                     Whenever we perform validations in our custom or extension controllers, we would need to display error messages if the user enters invalid data and these error messages can be constructed and displayed with the help of this Message class.
 If your application uses a custom controller or extension, you must use the message class for collecting errors.


Syntax:
In a custom controller or controller extension, you can instantiate a Message in one of the following ways:
ApexPages.Message myMsg = new ApexPages.Message(ApexPages.severity, summary);
        where ApexPages.severity is the enum that is determines how severe a message is, and summary is the String used to summarize the message.
For example:
ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.FATAL, 'my error msg');

ApexPages.Message myMsg = new ApexPages.Message(ApexPages.severity, summary, detail);
           where ApexPages.severity is the enum that is determines how severe a message is, summary is the String used to summarize the message, and detail is the String used to provide more detailed information about the error.

ApexPages.Severity Enum:

           Using the ApexPages.Severity enum values, specify the severity of the message. The following are the valid values:
1. CONFIRM
2. ERROR
3. FATAL
4. INFO
5. WARNING
All enums have access to standard methods, such as name and value.

Page Reference Class:
A PageReference is a reference to an instantiation of a page. Among other attributes, PageReferences consist of a URL and a set of query parameter names and values.
Use a PageReference object:

    1. To view or set query string parameters and values for a page
    2. To navigate the user to a different page as the result of an action method
      Syntax:
                   In a custom controller or controller extension, you can refer to or instantiate a PageReference in one of the following ways:

      Page.existingPageName       
                     Refers to a PageReference for a Visualforce page that has already been saved in your organization. By referring to a page in this way, the platform recognizes that this controller or controller extension is dependent on the existence of the specified page and will prevent the page from being deleted while the controller or extension exists.
      PageReference pageRef = new PageReference('partialURL');
                   Creates a PageReference toany page that is hosted on the Force.com platform. For example, setting 'partialURL' to'/apex/HelloWorld' refers to the Visualforcepage located at http://mySalesforceInstance/apex/HelloWorld. Likewise, setting 'partialURL' to '/' + 'recordID' refers to the detail page for the specified record.
        This syntax is less preferable for referencing other Visualforce pages than Page.existingPageName because the PageReference is constructed at runtime, rather than referenced at compile time. Runtime references are not available to the referential integrity system. Consequently, the platform doesn't recognize that this controller or controller extension is dependent on the existence of the specified page and won't issue an error message to prevent user deletion of the page.
      PageReference pageRef = new PageReference('fullURL');

      Creates a PageReference for an external URL. For example:

      PageReference pageRef = new PageReference('http://www.google.com');
      You can also instantiate a PageReference object for the current page with the currentPage ApexPages method. For example:
      PageReference pageRef = ApexPages.currentPage();

      Select Option Class:
      A SelectOption object specifies one of the possible values for a Visualforce selectCheckboxes, selectList, or selectRadio component. It consists of a label that is displayed to the end user, and a value that is returned to the controller if the option is selected. A SelectOption can also be displayed in a disabled state, so that a user cannot select it as an option, but can still view it.

      Syntax:
                In a custom controller or controller extension, you can instantiate a SelectOption in one of the following ways:
      SelectOption option = new SelectOption(value, label, isDisabled);

              where values is the String that is returned to the controller if the option is selected by a user,label is the String that is displayed to the user as the option choice, andis Disabled is a Boolean that, if true, specifies that the user cannot select the option, but can still view it.
      SelectOption option = new SelectOption(value, label);

             where value is the String that is returned to the controller if the option is selected by a user, and label is the String that is displayed to the user as the option choice. Because a value for is Disabled is not specified, the user can both view and select the option.

      Standard Controller Class:
               StandardController objects reference the pre-built Visualforce controllers provided by salesforce.com. The only time it is necessary to refer to a StandardController object is when defining an extension for a standard controller. StandardController is the data type of the single argument in the extension class constructor.
      Syntax:
      You can instantiate a StandardController in the following way:
      ApexPages.StandardController sc = new ApexPages.StandardController(sObject);

      COMMENTS

      BLOGGER
      Name

      Apex Apex Default Methods Apex Methods Apex_Collections Apps Batch Apex Books CRM eBooks Data Import Wizard Data Management DataLoader Dataloader.io Difference Between Error in Salesforce FAQ's FAQ's-Apex FAQ's-Apps FAQ's-CRM FAQ's-Data loader FAQ's-SOQL & SOSL FAQ'S-Triggers FAQ's-User Profile & Security FAQ's-VF Force.com Explorer Force.com Ide Formulas & Functions Integration Interview Questions Only Latest_Updates Limits&Best Practices Online-Training Reports and Dashboards Salesforce Deployment Salesforce Realtime Examples On Development Salesforce Realtime Task On Admin Salesforce Realtime Tasks Salesforce Realtime Tasks- Apex Salesforce Training Salesforce1 Mobile Sites SOQL Spring'14 Release Triggers User Profile & Security VF Tags VisualForce Winter'14 Release Wizard for Accounts/Contacts Workbench Workflows and Approvals
      false
      ltr
      item
      Sfdc Gurukul- All in one place for salesforce and force.com step by step tutorial for beginners: How to write message class in apex controllers?
      How to write message class in apex controllers?
      Message class in visualforce pages,syntax,apexpages.severity enum,conform,error,fatal,info,warning,page reference class,select options class,standard controller class
      Sfdc Gurukul- All in one place for salesforce and force.com step by step tutorial for beginners
      http://sfdcgurukul.blogspot.com/2013/07/how-to-write-message-class-in-apex.html
      http://sfdcgurukul.blogspot.com/
      http://sfdcgurukul.blogspot.com/
      http://sfdcgurukul.blogspot.com/2013/07/how-to-write-message-class-in-apex.html
      true
      4199533888133360731
      UTF-8
      Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS CONTENT IS PREMIUM Please share to unlock Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy