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
Akanksha CullenAkanksha Cullen 

Lookup Field - Restricting Duplicate Value Insertion

Hey,

I need to restrict the user from entrying any duplicate values in the database. I have a Members Object. It has an auto text field and and a member name lookup field which is related to User Object. I don't want any one to pick and add any user from the look field which is already there in my Members list. 

So I have not been able to add this rule to my object. I don't want to use any triggeers for this. Validation rules had not enabled to me do this so far. I also tried to add a filter criteria to the lookup filter. It is not letting me compare the values of Current Lookup Member Name field to Current Record Member Name field. 

Could anyone please suggest any workaround for this ?

 
Best Answer chosen by Akanksha Cullen
MithunPMithunP
Hi Akanksha Cullen,

You can achive this one by creating a Text(unique)  field and a workflow rule.

1. Create a Text field (Unique) on Members Object // Make sure to check unique checkbox while creating text field.
2. Create a workflow rule with below things
  Evaluation Criteria:   created, and every time it’s edited
  Rule Criteria: Criteria are met 
                         Record: Created Date Not Equal to Null
3. Add a workflow field Update Action
    In action insert/update new Text field with member name lookup field which is related to User Object.

Actually we have created Text field for unique values, when ever we create/update Members object records userId will store in our custom Text field, If you select same user second time it throws an error.

Let me know if you have any issues while implementing this.

Best Regards,
Mithun.

All Answers

MithunPMithunP
Hi Akanksha Cullen,

You can achive this one by creating a Text(unique)  field and a workflow rule.

1. Create a Text field (Unique) on Members Object // Make sure to check unique checkbox while creating text field.
2. Create a workflow rule with below things
  Evaluation Criteria:   created, and every time it’s edited
  Rule Criteria: Criteria are met 
                         Record: Created Date Not Equal to Null
3. Add a workflow field Update Action
    In action insert/update new Text field with member name lookup field which is related to User Object.

Actually we have created Text field for unique values, when ever we create/update Members object records userId will store in our custom Text field, If you select same user second time it throws an error.

Let me know if you have any issues while implementing this.

Best Regards,
Mithun.
This was selected as the best answer
Vijay NagarathinamVijay Nagarathinam
Hi,

It is possible in Apex trigger, I have the code for restrict the duplicte lookup. If you need let me know.
Akanksha CullenAkanksha Cullen
@Mithun - I don't want to add any text field to my Members Object as it would ask the user to add users by entering their names. I just want to use the lookup for adding members from the already existing User object. So I'd like this rule to be on my Member Name Lookup field rather than adding a new text field which will just add normal text values and not actually link it to the already existing users. 


@Vijay - If the Apex trigger works on the Lookup field, I'd love to have a look at it please.
MithunPMithunP
Hi Akanksha,

It will work as per your requirement, actually we need to create a text feild but no need to include that field in your page layout it will insert/update by workflow in background. In Pagelayout/UI your actual lookup field only appear. 

Best Regards,
Mithun.
Akanksha CullenAkanksha Cullen
@Mithun - That makes sense. And I was just trying to do that. But while creating the workflow rule, how to go about this - " action insert/update new Text field with member name lookup field which is related to User Object. How and where do I add this ? In the text option, right ? 
I am sorry for the trouble, I'm just new to Salesforce. 

"User-added image
MithunPMithunP
Hi Akanksha,

Yes Text option, In workflow field update you just select your Members object user lookup field for Text field.

It means, your lookup field and new custom text fields value should be same.

Make sure to activate your workflow before testing.

Best Regards,
Mithun.
Cha YangCha Yang
I tried this but it doesn't work for me because the workflow run after the duplicate rule. Any suggestions what i should do?
 
Ayesha Howla JAyesha Howla J
@Vijay Nagarathinam , If It is possible in Apex trigger, then plz give the code. Thanks in advance.

Regards,
Ayesha