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
MyGodItsColdMyGodItsCold 

How Do I: Limit # Contacts with Checkbox Checked to 2

I'm looking for advice on how to best implement the following:

A contact has a check box - a custom field. When the user checks the box, I want to run a query to see if there are 2 Contacts associated with the Account who have that box checked - if so, deny the ability to check the box & notify the user that s/he already has 2 Contacts checked.

I'm thinking a trigger, but in the ultimate implemenation, I'd like to tell the user:

Hey, here are the 2 contacts you've already got checked - demote one to promote the current one, or bail out.

So, this would seem to suggest an S-Control - but if I want to put it on the Contacts Pagelayouts, would that get into an override situation? And is that a matter of somehow cloning what's there, but just overloading the Save button?
cmarkcmark
can you write apex code in this instance (currently only in unlimited edition, i believe)?  if so, then you can override the save button.  if you don't, then i can't think of any options for you.  you can add an scontrol to the detail page which does the query, etc - but that has to be initiated manually.  so you'd save the third contact, press the button which fires the scontrol, and you'd get the message that there are 3 checked contacts...but that's pretty lame.
chris


Message Edited by cmark on 12-05-2007 08:02 PM
MyGodItsColdMyGodItsCold

Chris, Thanks for responding. Yesterday, I opened for testing a trigger which checks to see if there are two others with the check box checked, and if so, it aborts with a message. I can't wait for Visualforce to go to production! We did enough testing on it to confirm it was what we're hoping - but without firm time lines, we have disengaged.

 

cmarkcmark
Hello.  I didn't quite follow your message.  "I opened for testing a trigger?"  You're talking about Apex code?
Thanks
chris
MyGodItsColdMyGodItsCold

Sorry. Yes, I wrote an APEX trigger on Contacts. It's a Before Update trigger. I test the .old vs the .new values of the checkbox to see if it's just been checked (false to true), or unchecked (true to false). If checked, I query to see how many are currently checked.

We're in a pretty structured environment. We use multiple sandboxes, and when something is developed, we eventually move it into the sandbox with all the data (instead of strategically designed data points geared to hit one of each kind). That event I refer to as 'open for testing'. I've already tried to get it to fail & have come up short, so now it's time for our super-user / admin / owner team to test it.

In addition to structured migration from development to test to production, we engage version control - but allow for fast prototyping. We're getting better & better at this each day.