0

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?

5

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'}"

  • 1
    The actual final output needs to equal "true" for the disabled attribute to kick in. Visualforce considers everything else false, so the literal string "System Administrator != 'Account Manager'" does not match the literal string "true". – sfdcfox Jun 16 '15 at 16:21
  • @sfdcfox is the disabled attribute special in some way? I've been using that syntax for years in markup like: rendered="{!$Profile.Name == 'System Administrator'}" and it's always worked. – Mark Pond Jun 16 '15 at 16:42
  • 2
    Yes, that works, but the OP had the brackets in the wrong place. your answer is spot on, I was only including extra info. Instead of an error, disabled (and other boolean attributes) merely assume their default if they do not evaluate to the other condition. Try this: <apex:inputText disabled="Mickey Mouse" /> and you'll see what I mean. – sfdcfox Jun 16 '15 at 16:47
  • Try this example out as well, and observe the rendered HTML that occurs: <apex:page > <apex:form> <apex:inputText disabled="Mickey Mouse" /> <apex:inputText disabled="false" /> <apex:inputText disabled="true" /> </apex:form> </apex:page> – sfdcfox Jun 16 '15 at 16:50
1

Looks like everything needs to be in between the curly braces

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

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.