6

I have custom field which I use together with workflow to insure a unique key on two other custom fields. If user tries to enter duplicate values and workflow tries to populate duplicate value into this field then I am getting the following error message:

Error: Invalid Data. 
Review all error messages below to correct your data. 
Duplicate value on record: 40 (Related field: UniqueTitleAuthorKey__c)

Is there way I can manipulate this message and provide my own error message ?

1 Answer 1

2

You could do the validation with a before insert/udpate trigger and fire a custom error message from there.

// pseudocode
trigger validateBeforeInsertUpdate TheObj__c (before insert, before update)
{
  list keys = new list;

  for(record : trigger.new)
  {
     keys.add(record.fieldA + record.fieldB);
  }

  set existing = new set;

  for(result : select id, key from TheObj__c where key in keys)
  {
     existing.add(result.key);
  }

  for(record : trigger.new)
  {
    if(existing.contains(record.fieldA + record.FieldB))
    {
      record.addError('Duplicate value error message here!');
    }
  }
}
2
  • Yer, but then I am getting my message with all other system information around it, which is even uglier :)
    – vlr
    Nov 12, 2013 at 18:34
  • 1
    What information? You could also extend the Exception class, throw a custom exception from your trigger and catch that in the page controller to put a 'nice' message on the screen.
    – Matt Lacey
    Nov 13, 2013 at 21:26

You must log in to answer this question.

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