+ Start a Discussion
Alex Waddell 12Alex Waddell 12 

Prevent a record from saving if another record in same object has checkbox as true

Hello everyone,

I have an object called Patient_Physician__c where we associate Patient Accounts and Physician Accounts to eachother. I have a checkbox on the Patient Physician object that tells us if this physician is the primary care physician for the patient. The field is called Primary_Physician__c

I want to there to only be one primary care physician allowed in this object for each Patient Account, so that we dont have multiple physicians denoted as the PCP. Also a good thing to note, a Physician can be the PCP for any number of Patient's

I am not exactly sure which tool to use for this. I was thinking a validation rule but can a validation rule look at other records within that object and prevent the record from saving? Or would this be some sort of Apex trigger validation rule? 

I would love to hear your thoughts on this
Hi Alex,

What i can advice you is to create a formula field which allow you to get the value of the checkbox field.
And then use a validation Rule to prevent registration.
How ? 

First, you have to create a lookup field which get the record (from the same object Patient_Physician__c, lookup to himself), this is the only way to keep a link between those two records, then use the fomula field to get the Primary_Physician__c field value, and finish by create a validation rule based on the formula field (true or false).
I think tht this is the simplest way to accomplish this.

Do not hesitate to tell me if it's what you need.
I hope this helps.
Alex Waddell 12Alex Waddell 12

Thanks for the response. I had a few questions, is the formula field you are talking about on the Account object or on the Patient_Physician__c object

I have 2 lookup fields on the Patient_Physician__c object one for the Patient and one for the Physician. Do i need to make one more lookup to the Patient Account again or does the one i have serve the same purpose?

I advice you to use the same lookup relationship for your purpose, it's not necessary to create another field.
If the Patient Account field correspond to your record's target, no problem, use it.

Please mark this thread as SOLVED and answer as the BEST ANSWER if it helps address your issue.