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
Molson94Molson94 

<apex:repeat> Not rendering / showing values

Hello,

I am losing my mind trying to sort out why apex:repeat is not working on my visualforce page.
I've used apex:repeat before and never had any issue.

The VF page is loading, and the logs show that the SOQL list "repeatedList" has values.
The page loads fine, and nothing is shown in the apex:repeat section of the page.

Are there any other considerations I may be missing that will prevent apex:repeat from working?

VF Page:
<apex:repeat value="{!repeatedList}" var="a">
                <apex:outputText value="{!a.id}" />
</apex:repeat>
Controller:
public class cb_controller {
    public list<object__c> repeatedList {get; set;}
    
 public cb_controller(){
    list<object__c> repeatedList = new list<object__c>();
                
                List<object__c> soqlList = new List<object__c>([
                    SELECT id
                    FROM Object__c 
                    ]);
                
                for(Object__c x : soqlList){
                    repeatedList.add(x);
                    system.debug(x);
                }
                
}

Thanks in advance!
 
Best Answer chosen by Molson94
Suraj TripathiSuraj Tripathi
Hi Molson,
Try changing the Controller code to this. 

Controller :
public class cb_controller {
    public list<object__c> repeatedList {get; set;}
    
 public cb_controller(){
    
     repeatedList = new list<object__c>();
                
                List<object__c> soqlList = new List<object__c>([
                    SELECT id
                    FROM Object__c 
                    ]);
                
                for(Object__c x : soqlList){
                    repeatedList.add(x);
                    system.debug(x);
                }
                
}

I have tried in my org and it is working fine. Here it is my code.

VisualForce page: 
<apex:page controller="repeatClass">
    <apex:repeat value="{!actlist}" var="string" id="theRepeat">
			<apex:outputText value="{!string.id}" /><br/>
        	<apex:outputText value="{!string.name}" /><br/>
        	<apex:outputText value="{!string.phone}" /><br/>
	</apex:repeat>
</apex:page>

Controller :
public class repeatClass {
    public list <Account> actlist{get;set;}
    public repeatClass(){
        actlist = new List <Account>();
        List <Account> acclist = new List <Account>();
        acclist = [select id , name ,phone from Account Limit 10];
        for(Account act : acclist){
            actlist.add(act);
        }
        
        
    }
}

Screenshot :
User-added image


Hope it Helps you. Please mark this as solved so that it gets removed from the unanswered queue which results in helping others who are encountering a similar issue.

Regards ,
Suraj​

All Answers

Suraj TripathiSuraj Tripathi
Hi Molson,
Try changing the Controller code to this. 

Controller :
public class cb_controller {
    public list<object__c> repeatedList {get; set;}
    
 public cb_controller(){
    
     repeatedList = new list<object__c>();
                
                List<object__c> soqlList = new List<object__c>([
                    SELECT id
                    FROM Object__c 
                    ]);
                
                for(Object__c x : soqlList){
                    repeatedList.add(x);
                    system.debug(x);
                }
                
}

I have tried in my org and it is working fine. Here it is my code.

VisualForce page: 
<apex:page controller="repeatClass">
    <apex:repeat value="{!actlist}" var="string" id="theRepeat">
			<apex:outputText value="{!string.id}" /><br/>
        	<apex:outputText value="{!string.name}" /><br/>
        	<apex:outputText value="{!string.phone}" /><br/>
	</apex:repeat>
</apex:page>

Controller :
public class repeatClass {
    public list <Account> actlist{get;set;}
    public repeatClass(){
        actlist = new List <Account>();
        List <Account> acclist = new List <Account>();
        acclist = [select id , name ,phone from Account Limit 10];
        for(Account act : acclist){
            actlist.add(act);
        }
        
        
    }
}

Screenshot :
User-added image


Hope it Helps you. Please mark this as solved so that it gets removed from the unanswered queue which results in helping others who are encountering a similar issue.

Regards ,
Suraj​
This was selected as the best answer
Molson94Molson94
Hi Suraj,

Thanks for the reply. What is the difference in what i posted and what you posted? I was able to get this working properly only if i wrote out the "get" method instead of using the shorthand {get;set;}

Thanks!
Suraj TripathiSuraj Tripathi
Hi Molson,

The only difference is in Line no 5 of your Controller Code i.e 
list<object__c> repeatedList = new list<object__c>();

You have initialized the list in the constructor. Instead, you need to write only 
repeatedList = new list<object__c>();

Hope it Helps you. Please mark this as solved so that it gets removed from the unanswered queue which results in helping others who are encountering a similar issue.

Regards ,
Suraj