I want to render one page block section on the page to certain user only.

I want to render one page block section on the page to certain user only.

<apex:pageBlockSectionItem rendered="{!$User.Name == opp.Security_Officer_Name__c}">
<apex:inputfield />
</apex:pageBlocksectionItem>

above code gives me an error for $User.Name Error Message “Field Name does not exist. Check spelling.” and starange part is if I use $User.FirstName it works fine.

Does anyone know reason behind this? Any help is appreciated.

Many Thanks

Answer

That is strange, but my best guess is that the Name field is actually a composite field which gets some magic treatment in the backend. I notice that both FirstName and Lastname work, so perhaps you should use something like
{!$User.FirstName &' '& $User.LastName == opp.Security_Officer_Name__c}
or find a way to match on something other than Name…

Attribution
Source : Link , Question Author : Ricky , Answer Author : RenegadeCoder

Leave a Comment