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
Uttpal chandraUttpal chandra 

How to display message using java script?

Hi All,
I have VF page in which I have one command button if supose user insert the data suceesfully it should display message "Record is inserted" and if some error occur it should display message "Record is not created".
 
<apex:commandButton action="{!processSelected}" value="Run Template" onComplete="Refresh();"/>

Thanks in advance
DevADSDevADS
Hello Uttpal,

You can use pagemessages. 

Please see below code for your reference.
<apex:page controller="theController">
    <apex:pageMessages ></apex:pageMessages>
 </apex:page>
 
public class theController {
 
	public theController(){
	
		try{
			Account acc = new Account(Name='Test');
			insert acc;
			ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Success, 'Record Successfully created.'));
		}catch(Exception e){
			ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, e.getmessage()));ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, e.getmessage()));
		}
	}
}

Happy Coding!!
Uttpal chandraUttpal chandra
Hi Dev,
Right now that button is in POP up and also right now after clicking the POP it is refreshing the page and the code which you have have given is for simple button without POP up.

Regards,
Uttpal