function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
etechcareersetechcareers 

List Out Of Bounds:0..????

Hi:

   If a SOQL Query has no records I keep getting List Out Of Bounds:0..

 

How can I write a message stating to the user " There are no records for the filters selected" onto my VF Page???

 

Thanks

eTechCareers

Best Answer chosen by Admin (Salesforce Developers) 
imuino2imuino2

Do this

In your controller

Define a boolean variable

 

public Boolean renderError{get;set}

Then, after you get the List

 

   if (List.size() > 0){

        renderError = false;

   }else{

       renderError = true;

   }

 

Then in your page

 

<apex:outputPanel rendered="{!renderError}" layout="none">

         There are no records for the filters selected

</apex:outputPanel>

 

Also put the code in your page where the list is showed into an output panel

 

<apex:outputPanel rendered={!!renderError}" layout="none>

     your code here

</apex:outputPanel>

 

I hope it helps

Ignacio

All Answers

imuino2imuino2

Do this

In your controller

Define a boolean variable

 

public Boolean renderError{get;set}

Then, after you get the List

 

   if (List.size() > 0){

        renderError = false;

   }else{

       renderError = true;

   }

 

Then in your page

 

<apex:outputPanel rendered="{!renderError}" layout="none">

         There are no records for the filters selected

</apex:outputPanel>

 

Also put the code in your page where the list is showed into an output panel

 

<apex:outputPanel rendered={!!renderError}" layout="none>

     your code here

</apex:outputPanel>

 

I hope it helps

Ignacio

This was selected as the best answer
Jerry HongJerry Hong

it will be better to use .isEmpty();