function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
JayseJayse 

Formula Field returns different value in page layout to SOQL query

I have a simple formula field, below, which evaluates correctly when viewing it in the page layout.

 

if (User__r.Profile.Name = 'System Administrator', 'FIXED TRUE', User__r.Profile.Name)

 

The problem I have is when I try and lookup / reference the field in SOQL, i get a different result to what i see in the page layout, SOQL below:

 

select name, isActive__c from Incentive_Plan__c where user__c =:UserId

 

For the simple formula field logic above, the SOQL query returns the value 'PT1 ', I have no idea where it is getting this value from !

 

Hope someone can explain this behaviour.

 

Thanks

metaforcemetaforce

Is PT1 not the profile name of your input parameter UserId in SOQL?

Gunners_23Gunners_23

I'm  not sure whether the above is the formula you've created, if so you used assignment instead of equality

 

if (User__r.Profile.Name == 'System Administrator', 'FIXED TRUE', User__r.Profile.Name)

JayseJayse

The profile I am using is the standard system administrator, I have not created a profile "PT1", so as I said, I don't know where this value has come from.

 

Regarding the assignment vs. equality, I made the change and it's still returning the same result. 

   - as a side point on this one, wouldn't this also fail formula in the page layout and not just when evaluated as a result of running a SOQL query??

 

Thanks

Gunners_23Gunners_23

What is the value you gave for UserId in query and is_active__c is the name of formula field?

JayseJayse

I'm passing the ID for the user. The exact code in the apex class is

 

UserInfo.getUserId()

 

.. and yes, "isActive__c" is the API name for the formula field on the custom object I have created.

MarkLMarkL
I have this same exact problem. For some reason it seems that on the "Users" page the formula that relies on Profile.Name works properly, but when querying it via SOQL it does not, as if SOQL doesn't have access to Profile.Name but the User page in Salesforce does?

My formula:
IF(Profile.Name = "System Administrator", "IT", TEXT(Primary_Department__c))

This should be showing "IT" for system admins no matter what, and on the Users page it does, but querying it via SOQL always shows Primary_Department__c no matter what.

I've also tried ProfileId = "TheExactProfileSalesforceId" and this doesn't work either.

What is this? Why do formulas not have access to the Profile field on Users, but only when referring to them in SOQL not on the page directly?
MarkLMarkL

I made a new formula on the User that just shows Profile.Name, and what comes up is "PT1" -- It would appear that in formula context the System Administrator profile is actually named "PT1" .. Standard User is named "PT2" .. however if i try to edit my formula to be

IF(Profile.Name = "PT1", "IT", TEXT(Primary_Department__c))

that also doesn't work .. Not sure why it wouldn't work since a formula that simply returns Profile.Name gives you "PT1" for the system administrator profile.

What I was able to do to get this to work is off of the ProfileId directly in this way:

 

IF(LEFT(ProfileId,15) = "The15DigitSalesforceId", "IT", TEXT(Primary_Department__c))

Still quite perplexing...

Daniel Anthony 5Daniel Anthony 5
We have moved away from the image of India as a reflection of India as a land of fakirs lying on nail beds and snake makers with Indian rope tricks, maths geniuses, computer wizards, software gurus. Read more  Salesforce Certification Training (https://www.crsinfosolutions.com/salesforce-training-online/)
sd asssd ass
What is the best way to integrate the salesforce marketing scripts in general blog? I want to test for my website (https://dreamsofsnakes.com/) that hosted on WordPress.