function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
UrsfriendlyUrsfriendly 

How to add Message Class to class,Give me example

hi

 

 

Any one can help me......

 

How to Use Message class,to throw custom error messages on VF page?

 

 

Thank U

Pradeep_NavatarPradeep_Navatar

Tryout this sample code for getting addmessage class used in apex.

            VF Code:

                                                <apex:page controller="NewAndExistingController" tabstyle="Account">

                                                <apex:form>

                                                                <apex:pageBlock mode="edit">

                                                                   <apex:pageMessages/>

                                                                                <apex:pageBlockSection>

                                                                                                <apex:inputField value="{!Account.name}"/>

                                                                                                <apex:inputField value="{!Account.phone}"/>

                                                                                                <apex:inputField value="{!Account.industry}"/>

                                                                                </apex:pageBlockSection>

                                                                                <apex:pageBlockButtons location="bottom">

                                                                                  <apex:commandButton value="Save" action="{!save}"/>

                                                                                </apex:pageBlockButtons>

                                                                </apex:pageBlock>

                                                </apex:form>

                                                </apex:page>

 

            Controller code:

                                                public class NewAndExistingController

                                                {

                                                                public Account account {get; private set;}

                                                                public NewAndExistingController() {

                                                                Id id = ApexPages.currentPage().getParameters().get('id');

                                                                account = (id == null) ? new Account() :

                                                                [SELECT name, phone, industry FROM account WHERE id = :id];

                                                                }

                                                                public PageReference save()

                                                                {

                                                                                try {

                                                                                upsert(account);

                                                                                } catch(System.DMLException e) {

                                                                                ApexPages.Message myMsg = new

                                                                                ApexPages.Message(ApexPages.Severity.ERROR,e.getmessage());

                                                                                ApexPages.addMessage(myMsg);

                                                                                return null;

                                                                                }

                                                                                // After Save, navigate to the default view page:

                                                                                return (new ApexPages.StandardController(account)).view();

                                                     }

            }

UrsfriendlyUrsfriendly

Hi,

 

Thanks for this...

 

i was posted my complete requirement  to u........................please give me the reply for that...........

 

 

thank u