0

I'm trying to create a condition on a VF page to show me a field only if the two conditions are met. (I.e. I want to use the 'rendered' attribute twice)

Here is my code:

<apex:inputField value="{!pa.Permanent_User_ID_Collection__c}" 
rendered="{!!DRD_Submited + !recordTypeIsPPDetect == 'Platform_Detect'}"/>

And this is the error I get:

"Incorrect parameter type for operator '+'. Expected Number, Date, DateTime, received Boolean"

1

As mentioned you should use boolean methods as AND(value1, value2, ...) and NOT(value1)

<apex:inputField 
    value="{!pa.Permanent_User_ID_Collection__c}" 
    rendered="{!AND(NOT(DRD_Submited), recordTypeIsPPDetect == 'Platform_Detect')}"
/>

From design point of view you should not create complex conditions but instead create and use controller property that will isolate field visibility logic of type either Boolean (for single field) or Map<Id, Boolean> (for collection of records)

| improve this answer | |
1

You can use following:

<apex:inputField value="{!pa.Permanent_User_ID_Collection__c}" 
rendered="{!(!DRD_Submited && (recordTypeIsPPDetect == 'Platform_Detect'))}"/>
| improve this answer | |
  • The ! should only be used at the beginning of the merge field; elsewhere, it acts as a NOT operator, which is probably not the user's intent. – sfdcfox Nov 1 '16 at 16:17
  • Tried to execute what you suggested but I get a similar error: Incorrect parameter type for operator '='. Expected Boolean, received Text – Json Nov 1 '16 at 17:23
  • Please check the updated ans – Santanu Boral Nov 1 '16 at 19:32
0

For multiple conditions on a rendered attribute, you can also use AND and OR. Example: rendered="{!AND(condition_1,condition_2)}"

For your case, try rendered="{!DRD_Submited && recordTypeIsPPDetect == 'Platform_Detect'}", or rendered="{!AND(DRD_Submited,recordTypeIsPPDetect == 'Platform_Detect')}".

| improve this answer | |
  • It actually does compile, however it does not show the field on the VF Page. The field does exist because if I only use : rendered="{!!DRD_Submited} then the field appears. – Json Nov 1 '16 at 17:23
  • As someone commented in the other answer, multiple "!" signs will operate as negate effect. I have edited my answer to something that should work for you. – Mauricio Oliveira Nov 1 '16 at 18:46

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.