Activity Forums Salesforce® Discussions How to add Error messages on Vf Page using Apex in Salesforce?

  • How to add Error messages on Vf Page using Apex in Salesforce?

  • sushant

    Member
    February 16, 2017 at 2:53 pm

    Hi All,

    How to add Error messages on Vf Page using Apex in Salesforce?

    Thanks

  • Vikas Kumar

    Member
    February 17, 2017 at 6:00 am

    Hi sushant,

    You can do something like this

    public with sharing class ErrorMessageInVfController {
    public Account acc{get;set;}
    public ErrorMessageInVfController(ApexPages.StandardController controller) {
    acc = new Account();
    }

    public void save(){
    if(acc.name == '' || acc.name == null)
    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.FATAL,'Please enter Account name'));

    if(acc.AccountNumber == '' || acc.AccountNumber == null)
    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Please enter Account number'));

    if(acc.phone == '' || acc.phone == null)
    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'Please enter Account phone'));

    if(acc.site == '' || acc.site == null)
    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO,'Please enter Account site'));

    if(acc.industry == '' || acc.industry == null)
    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.CONFIRM,'Please enter Account industry'));

    }
    }

    for details go through http://www.sfdcpoint.com/salesforce/show-error-message-visualforce-page/

Viewing 1 - 2 of 2 posts

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos