2

XOR operator is not available in the Salesforce formula editor

I am looking to implement XOR using the IF operator, instead of doing this :

( A && !B ) || ( !A && B )

Any suggestion?

2 Answers 2

4

A XOR B is equivalent to IF(A,!B,B)

╔═══════╦═══════╦═════════════════════════╦════════════════════════════════╗
║ A     ║ B     ║ A XOR B                 ║ IF(A,!B,B)                     ║
╠═══════╬═══════╬═════════════════════════╬════════════════════════════════╣
║ true  ║ true  ║ true XOR true = false   ║ IF(true,!true,true) = false    ║
╠═══════╬═══════╬═════════════════════════╬════════════════════════════════╣
║ true  ║ false ║ true XOR false = true   ║ IF(true,!false,false) = true   ║
╠═══════╬═══════╬═════════════════════════╬════════════════════════════════╣
║ false ║ true  ║ false XOR true = true   ║ IF(false,!true,true) = true    ║
╠═══════╬═══════╬═════════════════════════╬════════════════════════════════╣
║ false ║ false ║ false XOR false = false ║ IF(false,!false,false) = false ║
╚═══════╩═══════╩═════════════════════════╩════════════════════════════════╝
3
  • 1
    This answer could use some additional detail. You've asserted that IF(A,!B,B) is equivalent (and it truly is, given that A and B are either boolean variables, or expressions that result in booleans), but where is your proof? Including a truth table that breaks down the evaluation of your IF() would be helpful.
    – Derek F
    Jun 13, 2017 at 12:43
  • Also, is this truly any better than the more traditional approach? Sure, it's a few characters shorter, but what effects does this have on the compiled size of the formula? What are the compiled costs of each Formula function would help in answering this.
    – Derek F
    Jun 13, 2017 at 12:48
  • @DerekF added the table, the compile size is about the same : 30 vs 32 (IF)
    – benahm
    Jun 13, 2017 at 13:04
2

If you just want the shortest way to write an XOR in a formula field, you could use this:

A!=B

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .