I have a custom VF page. When the page is refreshed, i need to display custom message in page "There is no record to save". when i am clicking save button message will be displaying. But i need without clicking the save button i want to show custom message. Can anyone help? Thanks
Page:
<apex:page standardController="Account" extensions="myaccountcontroller">
<apex:form >
<apex:pagemessages ></apex:pagemessages>
<apex:commandButton value="Save" action="{!Save}"/>
</apex:form>
</apex:page>
Controller:
public class myaccountcontroller
{
public string accId {get;set;}
public String finalamount {get;set;}
public myaccountcontroller(ApexPages.StandardController sc)
{
accId = ApexPages.CurrentPage().getParameters().get('Id');
doCalculation();
}
public void doCalculation()
{
Account AccObj = [SELECT Id,Name,Amount__c,Total_Amount__c FROM Account WHERE Id=:accId ];
system.debug('TotalAmount ###:'+AccObj.Total_Amount__c );
try{
finalamount = String.ValueOf(AccObj.Amount__c/0);
system.debug('finalamount###:'+finalamount);
}catch(Exception e)
{
if(e.getMessage() == 'System.NullPointerException: Attempt to de-reference a null object')
{
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Unite Price should not be empty'));
}
}
}
}