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
Clayto63Clayto63 

Prevent Duplicate Advice

hi, I am looking for advice on the best approach to prevent duplicates in a custom object. The scenario is this;
For each day, a customer may have many appointments of a certain type (Type1). Once an appointment for that day is added to the object (this is currently done via a process and flow), I do not want another to be added, but I do want to flag a boolean field to show that the customer has more than one appointment.
This is what I currently have;
cust   appointmentdate   type
001   01-03-2020           Type 1
001   01-03-2020           Type 2

I require;
cust   appointmentdate   type        other appointments
001   01-03-2020           Type 1     Yes
002   01-03-2020           Type 1     No

Any advice on the best way to approach this would be great. thanks in advance, 
ANUTEJANUTEJ (Salesforce Developers) 
Hi Clay,

One of the possible ways to prevent duplicate records is by using a trigger before insert.

Consider the scenario where we are preventing the account record from being inserted if an account record with the same name already exists.

https://developer.salesforce.com/forums/?id=906F0000000fyhvIAA

In the above link, it states a sample code that you can use for reference.

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_triggers_bestpract.htm

The above link gives a few of the best practices that you can use.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thank you!

Warm regards!
Anutej Poddaturi