+ Start a Discussion

Trigger to uncheck primary checkbox for multiple contacts


The Primary checbox field on our Contacts is enabled to "Checked" by default. If we want to add more contacts under the same account, then this should no longer be checked if it already has a primary contact. How can this be done using a trigger?

Nilesh Jagtap (NJ)Nilesh Jagtap (NJ)
You can write a trigger on contact object to check if it has primary contact.

1. Query all contacts related to account of current contact.
2. Check if any of these is primary one

You might have to consider few senarios like what happens when primary contact is deleted etc.

Good point on considering deleted primary contacts. But this is less likely to happen since users do not have that permission. I'll try out what you suggested. Thanks for your help!