0

I'm trying a rendered="{!If(Size<4,true,false)}" but I keep getting the following error: enter image description here

VisualForce Page

<apex:outputPanel rendered="{!If(avalistasSize<=4,true,false)}">    
           <div class="Avalista">
               <table>
                   <tbody>
                      <tr>
                       <apex:repeat value="{!Avalist}" var="item" rendered="true" > 
                        <td>   
                         AVALISTA:
                         {!item.contact.Name}<br/>
                         {!item.contact.CPF__c}<br/>
                         END.:&nbsp;{!item.contact.MailingStreet},&nbsp;CEP:&nbsp;{!item.contact.MailingPostalCode},&nbsp;{!item.contact.MailingCity}-{!item.contact.MailingState}<br/>
                          <apex:outputText rendered="{!display[item.Id]}">
                            Ass: {!item.contact.Procurador_do_Contato__r.Name}<br/>
                            CPF: {!item.contact.Procurador_do_Contato__r.CPF__c}
                          </apex:outputText> 
                          </td>
                        </apex:repeat>
                      </tr>
                   </tbody>
              </table>
           </div>
           </apex:outputPanel>

Controller:

public Integer avalistasSize  {get; set;}

public List <OpportunityContactRole> getAvalist(){ 
         if(avalista==null){
             avalista=[SELECT Id,contactId, contact.Name,contact.CPF__c,contact.MailingCity,contact.MailingStreet,contact.MailingState,
                       contact.MailingPostalCode, contact.Procurador_do_Contato__r.Name, contact.Procurador_do_Contato__r.CPF__c
                       FROM OpportunityContactRole 
                       WHERE OpportunityId =: idOpp
                      ];
         }  
        avalistasSize = avalista.size();

1 Answer 1

5

In your controller (or extension), you do not set a value for avalistasSize until getAvalist() is called.

I don't have any documentation to point to for the order in which merge expressions are processed in Visualforce, but I'd expect that it's the typical "left to right, top to bottom" order.

If that is the case, then that can provide an explanation for your error.

  • You use avalistasSize before setting a value
  • avalistasSize is null
  • Salesforce complains that you're trying to compare against a null value
  • You never hit the call to getAvalist() that would set avalistasSize

This can be fixed in more than one way, but the main point here is that you need to ensure that your properties have values before they're used (or as they're used, if lazy loading is appropriate for your scenario).

Given what you've shown us here, I'd probably just recommend turning List<OpportunityContactRole> avalista into an automatic property, and run the query to populate it (and avalistasSize) in the constructor of your controller/extension.

Bonus:
Things of the form if(<boolean expression>, true, false) can be reduced to simply <boolean expression>.
<apex:outputPanel rendered="{!If(avalistasSize<=4,true,false)}">
can become
<apex:outputPanel rendered="{!avalistasSize <= 4}">

1
  • Thanks, now I'm researching about automatic property, didn't know this concept @DerekF
    – Souza
    Commented Mar 14, 2022 at 20:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .