function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Ali FazeliAli Fazeli 

Duplicate

Hi all,
I have a custom object named xyz. It has text fields. The text fields are unique.The user can enter serialnummbers in this text fileds. How can I prevent the users to enter a serialnummber of a devie for obeject xyz 1 and xyz2.
The Users must enter the serialnummber of a device just in field serialnummber of object xyz1 the same serialnummber must not be entered for object xyz2 in field serialnummber.
Now a user can enter 1234 as serialnummber in first field of xyz1 and 1234 in 4th filed in xyz2 as serialnummber and it must not be allowed
Thanx
April 18, 
Lokesh KumarLokesh Kumar
Ali, is there any relationship between xyz1 and xyz2, If YES write a validation rule and check the field value vice verca.

~Lokesh
Waqar Hussain SFWaqar Hussain SF
Go to serialnummber field definition detail page by clicking the field name. 
click on Edit button and check the Unique checkbox on the field definition. 
Ali FazeliAli Fazeli
No there is no relationship bet both. Validation rule is to compare records from one Object. My friend told me, I should create a new object and in this new field as look up to xyz.
But I must ask him about details. i didn't understand.
Ali FazeliAli Fazeli
Waqar unique couldn't help me in this case. As said a user can enter 1234 as sn in first field of xyz1 and in another field of xyz2.
Waqar Hussain SFWaqar Hussain SF
Then you will need to develop a trigger on your object, which will check if both fields of the same object which is being inserted are same then will show an error message that you have duplicate value in the field.

See example
 
trigger xyzTrigger on XYZ1__c(before insert){

​
	for(XYZ1__c obj : trigger.new){
		set<string> dupCheck = new set<string>();
		if(obj.Field1__c != null)
		dupCheck.add(obj.Field1__c);

		if(!dupCheck.add(obj.Field2__c))
		obj.Field2__c.addError('Duplicate value found in field 2');
	}
}

 
Ali FazeliAli Fazeli
Thanx Waqar,
it's possible yes but there is a way with look up. I ask again my friend he told me I need to create a custom object and in this a field as look up to xyz.