You need to sign in to do that
Don't have an account?
Saie Shendage 7
Display alert message on successfully inserting the record through vf page
I am inserting one custom object on visualforce page form using custom controller. On clicking save button the record gets inserted. If the record is inserted successfully, I want to display one alert message 'Record saved successfully'/
Please help out.
Please help out.
In VF page you can use <apex:pageMessages> insted of javaScript button
add <apex:pageMessages /> in your vf page inside <apex:pageBlock>
your page
<apex:page controller="showsuccesscontroller" >
<apex:form >
<apex:pageBlock>
<apex:pageMessages />
<apex:inputText value="{!accName}" title="NAME"/>
<apex:commandButton value="Save" action="{!insertacc}"/>
</apex:pageBlock>
</apex:form>
</apex:page>
controller
public with sharing class showsuccesscontroller {
public string accName{set;get;}
public void insertacc(){
account acc=new account();
acc.Name = accName;
if (acc.Name == null || acc.Name == ''){
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Please enter Account Name'));
}
if (acc.Name != null && acc.Name != ''){
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.CONFIRM,'Record insert successfully'));
}
insert acc;
}
}
For further reference check the below,
http://www.sfdcpoint.com/salesforce/show-error-message-visualforce-page/
http://sfdcsrini.blogspot.com/2014/12/show-error-message-in-visualforce-page.html
Let me know if it helps you and close your query by marking it as solved so that it can help others in the future.
Thanks.
All Answers
In VF page you can use <apex:pageMessages> insted of javaScript button
add <apex:pageMessages /> in your vf page inside <apex:pageBlock>
your page
<apex:page controller="showsuccesscontroller" >
<apex:form >
<apex:pageBlock>
<apex:pageMessages />
<apex:inputText value="{!accName}" title="NAME"/>
<apex:commandButton value="Save" action="{!insertacc}"/>
</apex:pageBlock>
</apex:form>
</apex:page>
controller
public with sharing class showsuccesscontroller {
public string accName{set;get;}
public void insertacc(){
account acc=new account();
acc.Name = accName;
if (acc.Name == null || acc.Name == ''){
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Please enter Account Name'));
}
if (acc.Name != null && acc.Name != ''){
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.CONFIRM,'Record insert successfully'));
}
insert acc;
}
}
For further reference check the below,
http://www.sfdcpoint.com/salesforce/show-error-message-visualforce-page/
http://sfdcsrini.blogspot.com/2014/12/show-error-message-in-visualforce-page.html
Let me know if it helps you and close your query by marking it as solved so that it can help others in the future.
Thanks.