How to display a success message on Visualforce page when button is clicked?

How to display a success message on Visualforce page when button is clicked?

Sample Code:


Visualforce page:

  1. <apex:page controller=“Sample”>  
  2.       
  3.     <apex:form >  
  4.       
  5.         <apex:pageBlock >  
  6.           
  7.             <apex:pageMessages />  
  8.           
  9.             Testing Page Message  
  10.               
  11.             <apex:pageBlockButtons location=“bottom”>  
  12.               
  13.                 <apex:commandButton value=“Call” action=“{!check}”/>  
  14.                   
  15.             </apex:pageBlockButtons>  
  16.               
  17.         </apex:pageBlock>  
  18.           
  19.     </apex:form>  
  20.       
  21. </apex:page>  



Apex Class:

  1. public class Sample {  
  2.   
  3.     public Sample() {  
  4.           
  5.     }  
  6.       
  7.     public void check() {  
  8.       
  9.         ApexPages.addmessage(new ApexPages.message(ApexPages.severity.CONFIRM,‘Check button is clicked’));  
  10.           
  11.     }  
  12.       
  13. }  



Output:

Leave a Reply