Is it possible to create a nested IF formula field?

  • 1
  • Question
  • Updated 1 year ago
  • Answered
  • (Edited)
Is it possible to create a model formula field with nested IF statements?

I am trying to take the ObjectPermissions object and display profile names by using the profile ID that is given. 

If anyone has done this or something similar, I would greatly appreciate the help. 

Photo of Josef Lagorio

Josef Lagorio

  • 2,842 Points 2k badge 2x thumb

Posted 1 year ago

  • 1
Photo of Bill McCullough

Bill McCullough, Champion

  • 12,436 Points 10k badge 2x thumb
Josef,

I don't think you can do nested 'IF' statements.  I have used multiple formula fields to cascade the result of one formula field to another.  You can setup multiple 'IF' statements this way.

As it happens, I have created the same page that you are working on.  I setup a second model to get the PermissionSet names where the ProfileId is not null.  This model is the first in the list.

I then created 2 UI Only fields, one to lookup the Profile Name from the PermissionSet model and a second to check if the Parent.Name of the ObjectPermission starts with an 'X'.  If it does, I show the model lookup field.  If not, I show the Parent.Name from the table model.

Here is the model lookup formula.  Field is called 'ParentModelLookup':

MODEL_LOOKUP("PermissionSetsProfiles","Profile.Name","Id",{{ParentId}})

Here is the IF formula to set a UI only field to display the PermissionSet/Profile Name:

IF(STARTS_WITH({{{Parent.Name}}},"X"),{{{ParentNameLookup}}},{{{Parent.Name}}})

Thanks,

Bill
Photo of Josef Lagorio

Josef Lagorio

  • 2,842 Points 2k badge 2x thumb
Thanks a ton for this, Bill! Is there any way to include text along with the profile/permission set name? I can't figure it out using the formula.

IF(STARTS_WITH({{{Parent.Name}}},"X"),Profile:{{{ParentNameLookup}}},Permission Set:{{{Parent.Name}}})

Something along the lines of the bolded text above.
Photo of Bill McCullough

Bill McCullough, Champion

  • 12,436 Points 10k badge 2x thumb
Josef,

You just need to 'wrap' your Then and Else with single quotes:
IF(STARTS_WITH({{{Parent.Name}}},"X"),'Profile: {{{ParentNameLookup}}}','Permission Set: {{{Parent.Name}}}')

Thanks,

Bill
Photo of Josef Lagorio

Josef Lagorio

  • 2,842 Points 2k badge 2x thumb
Thanks a lot!
Photo of Amy Dewaal

Amy Dewaal, Official Rep

  • 8,200 Points 5k badge 2x thumb
Josef,

If Bill's way works for you, by all means, you can go with it. I felt I should also let you guys know that you can do nested if statements, though. You have to get the syntax just right, but it will work. There's a simple-ish example of a nested if on this post

Thanks!
Photo of Bill McCullough

Bill McCullough, Champion

  • 12,426 Points 10k badge 2x thumb
Amy,

Thanks for posting the sample.  I thought I had the syntax right when I tried it this morning.  I couldn't get it to work.  Must have needed more coffee.

Thanks!

Bill
Photo of Josef Lagorio

Josef Lagorio

  • 2,832 Points 2k badge 2x thumb
Thanks, Amy!