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
Rajasekhar TRajasekhar T 

How to show custom message on page instead of error message while . reloading the page?

I want to display the custom error message on page when page is reloading, page contains only save button. However, i want to show the only custom error message on page at that time i want to hide save button.
 
<apex:page standardController="Account" extensions="myaccountcontroller">
<apex:form >
<apex:pagemessages ></apex:pagemessages>
    <apex:commandButton value="Save" action="{!Save}"/>
</apex:form>
</apex:page>


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'));
        }
     }
  }


}

 
Raj VakatiRaj Vakati
Is alert will work for you on the page load ?? 

call an apex controller from a javascript button and and show the message on alert