0

shall i write apexPages.messages in the dependent classes of controller? is it displayed on the page if we it meets the criteria. Lets take i have vf page A, Which has B has controller and c is the dependent class for Controller. If i write ApexPages.message in c.

If the criteria meets shall it show it as error message on the vf page??

3
  • 2
    Yes it should .........
    – Eric
    Commented Dec 4, 2015 at 14:06
  • Try system.debug(ApexPages.currentPage()); in "c" dependent class method that you're calling from B. you will see the vf page reference.
    – sam_s
    Commented Dec 4, 2015 at 15:26
  • if the dependent class C is shared in non VF use cases, then I'd say "NO" and instead the dependent class should return a list of some inner class objects, similar to how Database.SaveResult works for database.xxx methods -- or -- throw exceptions to be caught by its callers. This is a bigger discussion centered around architecture patterns, covered elsewhere.
    – cropredy
    Commented Dec 4, 2015 at 17:57

1 Answer 1

1

PageMessages are not dependent on the Classes or how are they calling each other. They are related to current page instance, which is invoking the Class functions.

Therefore, when you are adding any pages messages, ApexPages page instance will collect all page messages and will display them on the page.

ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'Error: Invalid Input.');
ApexPages.addMessage(myMsg);

So to answer your question, it will show the error on the page.

You must log in to answer this question.

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