0

I'm trying to prevent duplicate records from being created. I have an application object with two relevant fields that looks like this:

Application__c:

  • Applicant (Lookup(User))
  • School (Lookup(School__c))

I'd like to only allow 1 application per applicant per school. An applicant can apply only once to each school. The applicant can apply to many schools.

I'm struggling a bit on where to start. What's the best way to go about preventing a new record?

I've started looking into Duplicate Rules, but when I try to set matching criteria the two lookup fields are not available, although other custom fields are.
If that's not going to work, I'm guessing I'll have to look at Apex triggers.

1

Via configuration

You can create a text field in application (36 characters) and mark it as unique.

On every save that field is populated by ApplicantOrUserId+SchoolId either via a workflow, before trigger or before save flow.

This way only one application can be created per Applicant per School

Via code

Create a trigger and calculate the same composite key and use add error when you find a duplicate.

2
  • Thanks @manjit, I'll take a look into those methods.
    – Dave
    May 11 at 16:47
  • I did as @manjit5190 suggested. I created a flow that updated a unique text field with UserId+SchoolId. When entering a duplicate Salesforce gives an error, not a very intelligible one, but It prevents duplicates none the less.
    – Dave
    May 13 at 12:28

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.