5

This is throwing me for a loop. I have a custom field on user, Backend_User__c. The formula is pretty simple:

IF(
 OR( Profile.Name = "API Only",
     Profile.Name = "Boldchat API Only",
     Profile.Name = "Business Intelligence (Custom)",
     Profile.Name = "Business Office (Custom)",
     Profile.Name = "Chat Representative (Custom)",
     Profile.Name = "Compliance (Custom)",
     Profile.Name = "GUAppDev API Only",
     Profile.Name = "IT (Custom)",
     Profile.Name = "IT - App Dev",
     Profile.Name = "Marketing (Custom)",
     Profile.Name = "Marketing User",
     Profile.Name = "Read Only All Records",
     Profile.Name = "Registrar (Custom)",
     Profile.Name = "System Administrator",
     Profile.Name = "System Administrator (Clone)",
     Profile.Name = "Read Only",
     Profile.Name = "Partner Community User"
   ),
TRUE,
FALSE
)

This appears to be showing correctly when I look at the user records. However, when I run SOQL against it, the values are not correct. For example: SELECT Name, Id, Profile.Name, Username, Alias, Bogus_User__c, IsActive, Backend_User__c FROM User returns false for a System Administrator. I go to the user record, and the field is checked. As it should be.

What is causing this?

  • Can u verify field level security? – Ayub Sep 5 '18 at 16:24
  • I can. I have read permission granted to every user. Also, it IS returning a value, False! – Chance Sep 5 '18 at 16:25
  • You can always replace IF(condition, true, false) with condition. It's already the exact same boolean value. – Adrian Larson Sep 5 '18 at 16:59
6

This is a Known Issue that can occur. It goes way back to the days when the standard profiles were named PTX, where X was a number. They still occasionally end up showing up in odd places, and you've found one of them.

As a matter of practicality, you don't need an "if" statement here, since your intent is to return true/false. You can also optimize this with a CASE statement. Here's the resulting formula:

1 = CASE(
    Profile.Name,
    "API Only", 1, 
    "Boldchat API Only", 1,
    "Business Intelligence (Custom)", 1,
    "Business Office (Custom)", 1,
    "Chat Representative (Custom)", 1,
    "Compliance (Custom)", 1,
    "GUAppDev API Only", 1,
    "IT (Custom)", 1,
    "IT - App Dev", 1,
    "Marketing (Custom)", 1,
    "Marketing User", 1, "PT5", 1,
    "Read Only All Records", 1,
    "Registrar (Custom)", 1,
    "System Administrator", 1, "PT1", 1,
    "System Administrator (Clone)", 1,
    "Read Only", 1, "PT3", 1,
    "Partner Community User" 1,
    0
)

This formula presumes that the bug will eventually be fixed, so includes the PTX variants for standard profile names that are affected. The full list is mentioned in this help topic.

  • Hmm interesting - one for the ancient bug that I've never heard of and two for your interesting logic... is it true that the system auto evaluates 1=0 as False? (it is false, of course, but the auto evaluation is unexpected) – Caspar Harmer Sep 5 '18 at 17:51
  • This looks great and I made the changes you suggest, but the problem still persists. Specifically for the system admin, which is mapped to PT1, correct? Would I be better suited to just use the IDs of the profile? And since this is a sandbox, would the profile IDs translate into Production (provided they were refreshed from production)? – Chance Sep 5 '18 at 17:55
  • 1
    @CasparHarmer Yes, it's a workaround since CASE cannot return true/false directly. It's often used as a shortcut when you want to compare one field to many values. All of the Boolean operators return a true/false result you can use directly. – sfdcfox Sep 5 '18 at 18:07
  • 1
    @Chance I would consider that a last resort, but should be acceptable if you can't find any other way. I would suggest experimenting with a formula that just returns Profile.Name directly to see what the results are, then use those values. – sfdcfox Sep 5 '18 at 18:08
  • 1
    @Chance If the checkbox is checked, the SOQL should find it, especially since you also queried Profile.Name. You may need to contact Support if the problem persists. I'm not sure there's much more we can do for you. – sfdcfox Sep 5 '18 at 18:33

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.