0

We have a unique field that blocks multiple records for being submitted for the same date. How do I customize this error message? Here is the section of my code grabbing the exception:

    public PageReference saveRecord(){
        try {insert fc;}
    catch(DMLException e){
            system.debug(e);
            ApexPages.addMessages(e);  
            return null;
        }

I simply have a tag for messages at the top of my VF page:

    <font color = 'red'>
        <apex:messages id="errorMsg" />
    </font>

enter image description here

4

1 Answer 1

0

Like i mentioned in my above comments you need to do your own error handling instead of depending on data uniqueness error from salesforce because it is not customizable.

You need to do something like below.

Visualforce page

<apex:pageMessages />

Apex Controller:

  ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'Error Message.');
  ApexPages.addMessage(myMsg); 

 (Or)

 ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,'Error Message.'));

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .