+ Start a Discussion
zen_njzen_nj 

how to properly use the render="..." syntax when I need to look at AND conditions

Hi folks

Not sure if this is visualforce question or apex question in general. But I wanted to render a section of the page only when certain criteria are met. In this case, the criteria is when two fields in my object have specific value.

In my situation, I am using Case object and also using the case standard controller. And in my visualforce page, I want certain sections to be rendered if say:
field 1 contains any value - field 1 is a multi-picklist field
field 2 to contains a specific text value - field 2 is a text field.

I can get the render logic working when I am basing it off just one of the field:

for example:

<apex:form rendered="{!case.field1__c != null}">
this would work and the section would be rendered depending on if field1 (a multi-picklist field) contained any value.

Also,
<apex:form rendered="{!case.field2__c == 'specific text value'}">
this also work and the section would be rendered when field2 (a text field) contains the specific value.

However, I can't seem to get it working so that the section would be rendered only when both conditions are met.
I tried the following variations below but not seem to be working, can someone shed some light on this please?

<apex:form rendered="{ IF (AND(!case.field1__c != null,!case.field2__c=='specific text value'),true,false}">

<apex:form rendered="{ (!case.field1__c != null) && (!case.field2__c =='specific text value') }">


jwetzlerjwetzler
try {! AND(case.field1__c != null, case.field2__c=='value') }

you've got too many ! in there.
zen_njzen_nj
thx. That worked like a charm.
Saleforce_newSaleforce_new

Hi Guys!

 

In my situation, I am using Opportunity object and also using the Opportunity standard controller. And in my visualforce page, I want certain sections to be rendered if say:
field 1 contains any value - field 1 is a number field
field 2 to contains a specific text value - field 2 is a multi-picklist


However, I can't seem to get it working so that the section would be rendered only when both conditions are met.
I applied the logic you mentioned  {! AND(Opportunity.field1 ! >= null, Opportunity.field2__c=='value') }

 

It is throwing the following error

The value 'null' is not valid for operator '>='

 

Can anyone please help?

zen_njzen_nj

If you are testing for that field 1 is not a blank/null value, then you can just use:

  {! AND(Opportunity.field1 ! = null, Opportunity.field2__c=='value') }

 

Since field 1 is defined as a number field, the only value that can be in it would have to be numeric (and not text).

 

But if you are testing that field 1 must be a number (and should be >= 0), then you could try:

 

  {! AND(Opportunity.field1 ! >= 0, Opportunity.field2__c=='value') }