For a currency field (say 10,2) , Salesforce displays a standard error message below the field as

Error: Number is too large.

My requirement would be to display an apex page message instead.

I have added apex error message in Save method . But it's not working.

if( cc.Amount__c != null){
    Integer numOfDigits = cc.Amount__c == 0 ? 1 : (1 + (Integer)Math.floor(Math.log10(Math.abs(cc.Amount__c))));
                                errorMain = true;
                                ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR, Label.Error);
                                return null;  

I could find other option as Try - Catch block. There is already a try catch for the entire set of operation . Within that , how can I insert this try catch ?

 try {

}catch(Exception ex){
            ApexPages.AddMessage(new   ApexPages.Message(ApexPages.Severity.ERROR,ex.getMessage()));

VF Page :

<apex:pageBlockSection columns="3" id="prd"  showHeader="true"  rendered="{!(Picklist value=='XXXXX')}">

                <apex:repeat value="{!AmountMap}" var="key" >               

                <apex:outputLabel value="Amount"/>
                <apex:outputPanel >
                <div class="requiredInput">
                     <div class="requiredBlock"></div>

                <apex:inputField value="{!AmountMap[key].Amount__c}" />


Controller :

try {

 //Other operations
 if(AmountMap != null && !AmountMap.isEmpty()){
 //field assignments 
 //other operations

 catch block

Here my condition will never satisfy if(AmountMap != null && !AmountMap.isEmpty()){ since error will be thrown by Salesforce beforehand.

  • 1
    You need to add a rerender in your markup. Since you haven't shared that, it is difficult to direct you on how to surface this error message on the front end. – Adrian Larson Feb 1 '17 at 3:19
  • Hi Adrian - I have updated the Question . – Vanilla_Sky Feb 1 '17 at 3:46
  • 1
    We need to see the save button. – Adrian Larson Feb 1 '17 at 4:08

You can't override this in Apex Code directly. The reason why is because the error occurs before any Apex Code is called, or even if no Apex Code is called at all. You can verify that's the case by checking your debug logs.

Here's a demonstration:

<apex:page standardController="Account">
        <apex:pageMessages />
        <apex:inputField  value="{!Account.AnnualRevenue}" />
        <apex:commandButton value="Continue" />

Example of Number is too large error

This feature is baked into the Visualforce engine, along with a lot of other automatic features, like making sure required fields are actually populated, etc.

If you want to provide a custom message, you'll have to either bind the value to a normal text field and parse it in Apex Code, or write JavaScript and parse the value before submission.

  • Ran into a similar issue . sfdcfox can you please provide an example for the binding into normal text field ? In this example , the value is kept in a map. – SFDCRookie Feb 3 '17 at 12:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.