[SalesForce] Formula syntax with multiple IF statements

I'm still very new to the formula syntax, and am hoping to achieve a series of nested IF statements. I'm a bit more experienced with bash, and what I'm trying to achieve would look something like this with that syntax:

if [ $GiftAidEligible ]; then
  if [ $PaymentType = "CAFDonate" ]; then
  elif [ $PaymentType = "JustGiving" ]; then

The field I'm trying to calculate with the above is called GiftAidAmount, a currency formula. The related static fields are:

-GiftAidEligible: A checkbox
-PaymentType: a picklist of string values
-GrossAmount: a currency field denoting the donation amount before fees
-Amount: another currency field denoting the donation amount after fees

I can explain the logic in a bit more detail if needed, but ultimately I'm after some help getting the above logic in to the correct syntax for my formula. Any pointers would be much appreciated.

Best Answer

The Salesforce formula field is a wacky one, that's true. I hate working with it, but do have a couple of pointers.

  1. The IF statement is pretty easy to get a handle on. Think of it as a 3 part function.
    IF(isTrue, then-thing, else-thing) If you want a nested condition, put that in the else-thing part. That would look like IF(isTrue, then-thing, IF(otherTrue, other-thing, other-then-thing))
  2. Use an external text editor.
    Using an external text editor we can take the above example (which is nigh impossible to read and makes me flashback to writing LISP) and turn it into this:




    And suddenly it becomes a lot more readable.

I personally like Notepad++ because it will automatically tab in when I hit enter and highlight opening/closing brackets when the cursor is on them. This makes it a lot easier to keep track of where you are in your nested conditions.
EDIT: Just remembered the BASH comment from the question.
kedit is my editor of choice on Linux (I prefer KDE) and I know that it has all the above functionality (and many more). Pretty sure gedit does too, for the GNOME users.

Related Topic