You need to sign in to do that
Don't have an account?
Developer129
Duplicate Validation Based on Two Fields
Hi,
Is there a way in salesforce to do duplicate validation based on two object fields
Thanx
function readOnly(count){ }
You need to sign in to do that
Don't have an account?
Hi,
Is there a way in salesforce to do duplicate validation based on two object fields
Thanx
Create a third field on the object perhaps called "unique check" or something like that. Define it to be Unique. You don't need to show it on the page layout, etc.
Use a workflow rule which fires whenever the object is changed (or whatever is appropriate for your case), and use a field update which sets the "unique" field with a concatenation of some kind of the two fields you want to check.
So, if a user enters a record with the same two field values as an existing record, the workflow would fire, the field update would be done, and there would be a uniqueness violation.
Best, Steve.
All Answers
Yes you can do it via a trigger, which fires on before insert event and before update. In the code you can check if either of these field value exist if yes, then raise an error something like below:-
sObj[] Arr=[select id, name from SObj where field1=: trigger.new[0].field1 or field2=: trigger.new[0].field2];
if(Arr.size()>0)
{
trigger.new.field1.addError('Duplicate value');
}
Did this answer your question? if so, please mark it solved.
Create a third field on the object perhaps called "unique check" or something like that. Define it to be Unique. You don't need to show it on the page layout, etc.
Use a workflow rule which fires whenever the object is changed (or whatever is appropriate for your case), and use a field update which sets the "unique" field with a concatenation of some kind of the two fields you want to check.
So, if a user enters a record with the same two field values as an existing record, the workflow would fire, the field update would be done, and there would be a uniqueness violation.
Best, Steve.