Supposed I have a guestList__c Object. Then I have another object called as guest__c which is related to guestList__c,Contact or Lead objects. From the name of the object itself, guest__c store the record which can either be contact or lead. Now what I want do is to trap if a particular guest record already exist.What is best solution for this ? Is it possible using validation rules ? workflow rules ? trigger and etc. ? Please give your idea about this. In addition, this scenario is quite similar with the campaign,campaign member,Contact/Lead relationship. The difference is that it is a custom object.

  • How do you differentiate two guest names from each other? By Name? Dec 4, 2015 at 3:45
  • @Salesforcesmarty guest can be differentiate using the combination by either : 1. guestList__c and Contact 2. guestList__c and Lead Meaning if you insert a new guest whose (guestList__c and Contact) OR (guestList__c and Lead) exist, it will give an error that it already exist. Name is just an auto number.
    – Hope
    Dec 4, 2015 at 3:50

1 Answer 1


This is a typical scenario where you want to identify duplicates based on the field values.

  1. Create a new field called, guestUniqueName and mark it as unique field

  2. Setup a workflow rule to fire on "Every time a record is created or updated"

    • Entry criteria would be Created Date Not equal to blank, so that it is always true
    • Create a field Update action and set the value of guestUniqueName using formula editor


    • Activate the workflow

  3. Save a record with duplicate values and your guestUnique name will throw error

Note: This will not work for existing values, as guestUniqueName is empty for that. To make it work for existing guests, run an update script to update all existing guests, so that workflow will update it.

Update [select id from Guest__c Limit 10000];
  • thank you. I will get back to you after I try this method.
    – Hope
    Dec 4, 2015 at 4:28
  • I have something weird experience here. If I used your code if(isNull(Lead__c),GuestList__c+''+Contact__c,GuestList__c+''+Lead__c) I can only concatenate the GuestList__c and the Lead__c but not the Contact__c. I try to use the Contact__c as the condition and only the GuestList__c and Contact__c are concatenated. Why is this ?Please help
    – Hope
    Dec 4, 2015 at 8:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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