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

Apex error message through normal function



Can a normal function send an apex error message to the Visualforce Page.


EX : 

public void abc (){


 ApexPages.addmessage(new ApexPages.message(ApexPages.severity.error,'Error!!!!!!));








No, you cannot send error msg to page from any class. Class must be set either as controller or extensions.

here the context of class does matter.


Hi Alok_vibrant,


I have set the above class a s an controller, but the method which is passing the message to VF shoud it  have a return type as "Pagereference" or can it be anything.


Thanks in advance.




Kavya - As i guess this method is being execute on some of the event from page like button click right ?

Return type of method can be either PageReference or void, apart from that you also need to include <apex:pageMessages/> vf tag in the page, probably top of the page.