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
RossKRossK 

APEX:repeat tag - Not working with a list of objects where the objects are not sObjects

Hello!

 

I have a class that I created.  The objects from this class are in a list and I am unable to display the list using the APEX repeat tag.  See the code below.  When I try to save the visualforce page, I get the following error.


Error: Unknown property 'repeatCon.objQuestion.Name'

 

My question is does Apex:Repeat support collections of non-SObject objects? If yes, what am I doing wrong? If not is there a work around?

 

<apex:page controller="repeatCon" id="thePage">
    <apex:repeat value="{!listquestions}" var="q" id="theRepeat">
        <apex:outputText value="{!q.Name}" id="theValue"/><br/>
    </apex:repeat >
</apex:page>

<!-- Controller -->

public class repeatCon {
    public class objQuestion{
    public string Name;
    public string SearchLabel;
   } 
    public list<objQuestion> listquestions {get; set;}
    
public repeatcon(){
      listquestions = new list<objQuestion>();
      objQuestion a = new objQuestion();
      objQuestion b = new objQuestion();
      a.name='a';
      a.SearchLabel='a';
      b.name='b';
      b.SearchLabel='b'; 
      listquestions.add(a);
      listquestions.add(b);
    }

}

 Thank you so much!!!

Best Answer chosen by Admin (Salesforce Developers) 
iRamos99iRamos99

To answer you question... Yes, you can use the apex:repeat tag with objects that are not sObjects.

 

Now I think that you're getting an error because you haven't set a get method for the name variable in the objQuestion class. Try this:

 

public class objQuestion{
    public string Name{get; set;}
    public string SearchLabel{get; set;}
}

All Answers

iRamos99iRamos99

To answer you question... Yes, you can use the apex:repeat tag with objects that are not sObjects.

 

Now I think that you're getting an error because you haven't set a get method for the name variable in the objQuestion class. Try this:

 

public class objQuestion{
    public string Name{get; set;}
    public string SearchLabel{get; set;}
}
This was selected as the best answer
souvik9086souvik9086

Hi,

 

try this

 

public class repeatCon {
public class objQuestion{
public string Name;
public string SearchLabel;
public objQuestion(string N,string S){
Name = N;
SearchLabel = S;
}
}
public list<objQuestion> listquestions {get; set;}

public repeatcon(){
listquestions = new list<objQuestion>();
listquestions.add(new objQuestion('a','a');
listquestions.add(new objQuestion('b','b');
}

}

 

If this post solves your problem kindly mark it as solution. if this post is helpful please throw Kudos.

Thanks

RossKRossK

This solves it.  Thank you so much.