I have the below implementation:


public class myClass{
public Boolean conSize {get;set;}

public void searchCon(){
    //Some code

        //Some code
        conSize = true;
    } else {
        conSize = false;

VF page:

<apex:outputPanel rendered="{!conSize}" >
     //Display contacts
</apex:outputPanel />

<apex:outputPanel rendered="{! !conSize}" >
    //Display 'No contacts retrived'
</apex:outputPanel />

But every time the page loads, I get my error message (which supposed to display only after verifying if the contacts size is != 0) even before my button click for querying the Contacts. What I am missing here?

1 Answer 1


This is probably an order-of-operations issue. I'm presuming that searchCon() does not get invoked until some user input or action takes place, while the getter for conSize is called during the initial page render.

I'd suggest implementing an actual getter (rather than letting the compiler synthesize it) and embedding the logic there, rather than setting the property during some other operation. It'd look something like this:

public Boolean conSize { 
    get {
        return conList != null && conList.size() > 0;
    private set;
  • 2
    even better if the variable was named hasContacts rather than conSize
    – cropredy
    Nov 6, 2019 at 22:50

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.