[SalesForce] Conditional disabled fields in visualforce

I need to make fields disabled on a visualforce page to those that do not have the profile name of Account Manager, but it is not working.

<apex:inputCheckbox value="{!Account.Vitality_Health_Review_Yes__c}" styleClass="chk-control hasAdditionalInfo" disabled="{!$profile.Name} != 'Account Manager'"/>(Yes/No)

Could this be because I am an administrator and I am higher than Account Manager in the hierarchy?

Best Answer

It appears that you're trying to get VF to render disabled="true" when the current user doesn't have a profile name of 'Account Manager'...

A little background: {! } is merge syntax, where the VF engine will evaluate the statements within the brackets during it's render of the data.

What you're probably seeing in your rendered markup is something along the lines of disabled="System Administrator != 'Account Manager'" and that's because the only part being evaluated by the VF renderer is the profile name, not whether it's equal to 'Account Manager'.

If you change your markup and move the closing bracket to the end of the statement, you'll be in business.

disabled="{!$profile.Name != 'Account Manager'}"

Related Topic