2

I have a beginner's question..

I'm trying to make a VF PageBlOckSection render by the following logic:


IF Opportunity.Cancellation__c == TRUE AND Opportunity.Paid_Upfront__c == TRUE than Render 2 fields (Amount and Expiry Date)

IF Opportunity.Cancellation__c == TRUE AND Opportunity.Paid_Upfront__c == FALSE than Render 1 fields (Expiry Date)

IF Opportunity.Cancellation__c == FALSE AND Opportunity.Paid_Upfront__c == TRUE than Render 2 fields (Amount and Expiry Date)

IF Opportunity.Cancellation__c == FALSE AND Opportunity.Paid_Upfront__c == FALSE than do not render.


However I cannot make it work by the desired logic... I'm using this code: I'll appreciate any advice!

Thanks, Jonathan


        <apex:pageBlockSection title="Please fill the Expiry Date & Upfront Amount" columns="1" rendered="{!IF(AND(!Opportunity.Paid_Upfront__c == TRUE, !Opportunity.Cancellation__c != TRUE), TRUE, FALSE)}">

            <apex:inputField value="{!opportunity.Subscription_Expiry_Date__c}"/>
             <apex:inputField value="{!opportunity.Amount}"/>
        </apex:pageBlockSection>


        <apex:pageBlockSection title="Please fill the Expiry Date" columns="1" rendered="{!IF(AND(!Opportunity.Paid_Upfront__c == FALSE, !Opportunity.Cancellation__c != TRUE), TRUE, FALSE)}">

            <apex:inputField value="{!opportunity.Subscription_Expiry_Date__c}"/>
        </apex:pageBlockSection>


        <apex:pageBlockSection title="Please fill the Expiry Date" columns="1" rendered="{!IF(AND(!Opportunity.Paid_Upfront__c == TRUE, !Opportunity.Cancellation__c == TRUE), TRUE, FALSE)}">

            <apex:inputField value="{!opportunity.Subscription_Expiry_Date__c}"/>
             <apex:inputField value="{!opportunity.Amount}"/>

        </apex:pageBlockSection>


    </apex:pageBlock>
</apex:form>

1 Answer 1

4

Once you are in a Visualforce {! } expression fields are referenced without a further ! (and a ! prefix becomes shorthand for a NOT function). Also the result of the AND function is already a boolean so the surrounding IF is not needed.

So for "paid upfront and cancellation" and "not paid upfront and not cancellation" the expressions can be:

rendered="{! AND(Opportunity.Paid_Upfront__c, Opportunity.Cancellation__c) }"
rendered="{! AND(NOT(Opportunity.Paid_Upfront__c), NOT(Opportunity.Cancellation__c)) }"

If you prefer operators over functions, this equivalent form also normally works:

rendered="{! Opportunity.Paid_Upfront__c && Opportunity.Cancellation__c }"
rendered="{! !Opportunity.Paid_Upfront__c && !Opportunity.Cancellation__c }"
0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.