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 ?

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!');
    }
  }
}
  • Yer, but then I am getting my message with all other system information around it, which is even uglier :) – vlr Nov 12 '13 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 '13 at 21:26

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.