<apex:pageBlockSection id="abcd" title="Closed Lost Information" rendered="{!(Opportunity.StageName=='Closed Lost')}">
        <apex:inputField label="Opportunity Name" value="{!Opportunity.Reason_Lost__c}"/><p/>

I am new to salesforce and I am having below question. As shown in above snippet, I need to render the "apex:pageBlockSection" if StageName value is equal to 'Closed Lost'. (StageName is a picklist of standard object opportunity)

Here the condition is not returning proper true or false value to render or hide the "apex:pageBlockSection" .

Can anybody please help me to figure out what is wrong with my approach ?

Thanks in advance :)

  • Use a Boolean variable instead of hard coded directly pick list value.And to set value to Boolean variable create an extension or custom controller and create a condition may be it works @user3240292 – Pavan tej Mar 30 '16 at 14:23
  • rendered="{!(Opportunity.StageName='Closed Lost')} ? (single equal sign?) – kurunve Mar 30 '16 at 14:38
  • I am using == for equality comparison . – user3240292 Mar 30 '16 at 14:42
  • 1
    Suggest you include <apex:outputField value="{!Opportunity.StageName}"/> in the page too while debugging to be sure of the value. – Keith C Mar 30 '16 at 14:46
  • 4
    Is the record you are testing with definitely 'Closed Lost' at the point you are rendering this component? i've mocked up this example quickly and it looks to work correctly with the syntax you've given. – Michael Fleming Mar 30 '16 at 14:47

Normally, you'd use a boolean variable, but you can also use an If statement to achieve the same results. Try the following for the rendered expression:

rendered="{!If(Opportunity.StageName='Closed Lost',true,false)}
  • 4
    As Opportunity.StageName=='Closed Lost' is already a boolean expression, I don't see why wrapping that boolean in a boolean function will help. Can you explain? – Keith C Mar 30 '16 at 14:34
  • I also tried using rendered="{!If(Opportunity.StageName=='Closed Lost',true,false)} – user3240292 Mar 30 '16 at 14:43
  • My bad, should have been one = sign. Have edited answer. – crmprogdev Mar 30 '16 at 14:43
  • 1
    Do you mean = (single equalto) sign will be used for comparison instead of == ? – user3240292 Mar 30 '16 at 14:45
  • Yes, that's exactly what I meant to say and post when I copy pasted. Apologies for the misdirection. Is simply a workaround if your original code didn't work. – crmprogdev Mar 30 '16 at 14:46

it got solved..by making below change :

<apex:outputPanel id="abcd"> 
<apex:pageBlockSection title="Closed Lost Information" rendered="{!opportunity.stageName == 'Closed Lost'}" > 
<apex:inputField label="Opportunity Name" value="{!Opportunity.Reason_Lost__c}"/><p/> 

i.e moved renedered attribute under pageblock section and rendered block under outputpanel

  • Just so you know I tried the rendered attribute on outputpanel and it is working for me. There really is no need to move to the pageBlockSection. – javanoob Mar 31 '16 at 5:45
  • This answer only makes sense if the issue was a rerender and not the initial rendering. During the initial render it will be evaluated properly but the original question if you try to rerender the pageblocksection it will not work. Maybe the question did not adequately describe the problem – Eric Mar 31 '16 at 5:53

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.