0

testfield__c is a picklist value and I want to make it non-editable if it is an US Account and not a business profile. I am doing in this way but it is hiding the field but not making it non-editable. I tried removing the apex: inputField and it worked but it is failing for other Accounts (UK etc.)

<apex: pageBlockSection title="{! ($Label.MyAccount)}" collapsible="false" id="AccountSectionId">
    <apex: outputField value="{! account. testfield__c}" rendered="{!!if ((isUSAccount && isSBusinessProfile), true, false)}"/>
                    <apex: inputField value="{! account. testfield__c}" rendered="{! if ((isBusinessProfile &&! isUSAccount), true, false)}"/>

Can anyone let me know where I am wrong?

1

When you have two Boolean variables, you have a total of four discrete outcomes: false/false, false/true, true/false, and true/true. You've only written logic for two of the four possible outcomes; the remainder will not show any field at all.

You also have a few bugs:

{!! IF(...

The extra ! is treated as a NOT operator, so you're actually inverting the logic.

Generally speaking, instead of writing {!IF(..., TRUE, FALSE)}, you should just write the condition: {!...}, which is easier to read. I also recommend using NOT(...) instead of !, simply because it's more obvious within a formula.

It appears that you really wanted to do this:

<apex:outputField value="{!account.testfield__c}" rendered="{!isUSAccount && NOT(isBusinessProfile)}" />
<apex:inputField value="{!account.testfield__c}" rendered="{!NOT(isUSAccount) || isBusinessProfile}" />

Using this pattern, we've covered our four possible conditions:

          Business Profile?
            TRUE   FALSE
           +------+------+
      TRUE | EDIT | R/O  |
 US?       +------+------+
     FALSE | EDIT | EDIT |
           +------+------+
| improve this answer | |
  • Thanks for the clear explanation. If US account is TRUE and Business Profile is TRUE it should be Read only R/O. The upper row should be R/O and lower row should be EDITABLE. – sri Jul 21 '17 at 0:40
0

apex:selectList has a disabled attribute that you can use instead of rendered. https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_selectList.htm

| improve this answer | |

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.