Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

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 ?

share|improve this question

1 Answer 1

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!');
    }
  }
}
share|improve this answer
    
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. –  LaceySnr Nov 13 '13 at 21:26

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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