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){
            return null;

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

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

enter image description here


1 Answer 1


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(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 .