3

I need to make a selection of Gender. [ ] Female [ ] Male.

Either one of them must be selected.

I used following formula for validating.

AND( Female__c = TRUE ,  Male__c  = TRUE )

Using this, I can select only one but I am unable to get exact functionality it is doing?

6

Validation rules trigger when the result is true, so you're looking for one of:

NOT(Female__c = Male__c)

-- or --

Female__c != Male__c

This will result in the validation rule triggering only when both or neither are selected. You don't need to compare checkboxes to true or false, by the way, since they're already Boolean values.

If you want a truly XOR-feeling way of doing it (say, if you needed this for a picklist), then you'd want:

(Male__c && Female__c) || (NOT(Male__c) && NOT(Female__c))

-- or --

OR(AND(Male__c, Female__c), AND(NOT(Male__c), NOT(Female__c)))

You can also use some basic math to make sure just one box is checked:

1 != IF(Male__c,1,0) + IF(Female__c,1,0)

This is probably the closest to a "pure" implementation of XOR you'll find.

  • I didn't the question properly, totally missed the point :) – Boris Bachovski Apr 22 '15 at 3:41
  • @Bachovski It's okay. I've done that before, too. Certainly does make one feel sheepish! – sfdcfox Apr 22 '15 at 3:49
  • 2
    It's what happens when a developer is stuck looking into data migration spreadsheets! :) – Boris Bachovski Apr 22 '15 at 3:50

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.