Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have three different text boxes(Email, Work Email, and Other Email) to enter email addresses. I created a custom field of type "Formula". I need it to loop through the three email(s) and return one email address, the first one it sees, and ignore the rest. I'm using IF statement but I don't seem to get it to work? Any help and suggestions is much appreciated.

share|improve this question
can you post your IF statement and logic on how the IF's should work? – Rao Aug 28 '14 at 18:32
up vote 4 down vote accepted
BLANKVALUE(Field1, BLANKVALUE(Field2, Field3))

This is a bit easier to read than nested IF statements. BLANKVALUE takes two parameters, and returns the first (left) parameter if it's not blank, otherwise the second (right) parameter.

share|improve this answer
+1. Much cleaner than my nested IF's. Wish I had thought of it :) – Chris Duncombe Aug 28 '14 at 18:40

If you literally just want to return one of them, not really caring which one if more than one has data, then something like this will work


If there's a value in the Email__c field, it uses that, regardless of whats in the other 2 fields. If theres nothing in the Email__c field, it moves on to the Work_Email__c field, and if theres something in that, it uses it, regardless of whats in the Other_Email__c field. If Work_Email__c is blank, it uses the Other_Email__c field, if it has a value. If all 3 are blank it returns null.

share|improve this answer
There's really no need for the third IF, since if Other_Email__c were null, it'd be the same net result, but a larger total compiled size. – sfdcfox Aug 28 '14 at 18:41
You are correct, updated to reflect. – Chris Duncombe Aug 28 '14 at 18:42

I know you've chosen an answer, but this might be a better way

 selectedEmail = email ? workEmail : otherEmail;

Which is the syntax for the ternary operator.

share|improve this answer
Thanks for your answer Jeremy. I tried similar approach but return isn't supported by Salesforce. – Achaa Aug 28 '14 at 20:39
Can you declare and assign variables? The return keyword is only included there because the question used the word "return", ...oh, and because I made a faulty assumption. I may be using SF soon, so I'm learning, starting today. Answer edited. – Jeremy Anderson Aug 28 '14 at 21:22
Can you have a buffer for loading a few things after you return from that method. Using email as ternary, there are lot of unfair load of primitive variables. Checking the value after the buffering and returning your ternary value would be better. I still don't think it's part of a salesforce issue though. Perhaps Scala or Haskell? – InstructedA Aug 29 '14 at 6:54

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.