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
JaiminJaimin 

HOW TO MAKE A LOOKUP FIELD UNIQUE IN CUSTOM OBJECTS

I am creating two custome objects (Employees, Device).
Create a Lookup relationship to assign a device to the employee. Employee can have multiple devices but Device have only one employee.
After assign the device to the employee that device can not be reassign till device can free.

How to make a Lookup relationship unique.
VineetKumarVineetKumar
I guess this would already be unique in the sense, the device will always be having only one employee value populated on the lookup.
Can you elaborate a bit more on it?
JaiminJaimin
Objects.
1. Employees
2. Device
3. Assign

In Assign Tab, Create Master-Relationship with Employees and Lookup with Device.

I am trying to do like these in assign oobject when device assign to employee.
Employee          Device
E1                     D1
E2                     D2
E3                     D1 (Error: This device already assign)
VineetKumarVineetKumar
At first look it looks like a flaw in your architecture, not sure about the other requirements associated to them.
Here with the Assign Object, you have create a Many to Many relationship (junction object).
But what you are actually required as per your statement is a One(Employee) - Many(Devices) relationship. Perhaps a simple lookup or a MD relationship should have worked here.

But still if your architecture requires this structure, what I can suggest you it to create a flag field on Device (isAssigned), which will be populated using a trigger, as soon a Device is associated to an Assign object the trigger will update this flag as true.
And then write a validation rule on Assign to not associate itself to a device if this flag is checked.

Let me know if it helped.