+ Start a Discussion
kavya.ax1320kavya.ax1320 

Apex error message through normal function

Hi,

 

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!!!!!!));

 

}

 

Thanks.

Alok_NagarroAlok_Nagarro

Hi,

 

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.

kavya.ax1320kavya.ax1320

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.

 

 

Alok_NagarroAlok_Nagarro

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.