I have an apex class that contains a method that generates a list of objects. I want to display this list of objects on a visual force page in order to test the data that the method is generating. In order to make the list available to the page, I created another method in the class that has a return type of pageReference:

 public pageReference createCampaignFromPage(){
          campaignMembersRet = addCampaignMembers();
          return null;

This method calls the method addCampaignMembers() which returns the list in question. The return value of addCampaignMembers() is stored in public List<CampaignMember> campaignMembersRet {get; set;} which is made publicly available for the visualforce page to use.

Inside of the visualforce page, I have the code:

<apex:page controller="CreateCampaign"   >
<apex:form >
     <apex:pageBlock title="Quick Edit: ">
        <apex:pageBlockButtons >
            <apex:commandButton action="{!createCampaignFromPage}" value="Save"/>
        <h1>Hello World</h1> 

    <apex:outputText value="{!testvar}" id="theValue"/><br/>
    <apex:repeat value="{!campaignMembersRet}" var="string" id="theRepeat2"> //It appears that this loop isn't being entered.
        <apex:outputText value="{!string}" id="theValue3"/><br/>


This should print out attributes of the List of objects iteratively when the button is pressed, but instead, the markup for the page is displayed without the data. There are two errors in the dev console including one regarding the logo for the page not being displayed and the other being Invalid 'X-Frame-Options' header encountered when loading. I'm not sure if this would be the issue causing the text to not appear in the loop.

What could be causing the problem? Is there anything here that stands out as being incorrect?

EDIT: Image of preview from dev console

enter image description here

  • You can't call Apex (System.debug) inline in Visualforce. You also appear to be trying to iterate over something that's not a collection by including an <apex:dataList> inside an <apex:repeat>. I'm surprised this compiles, but from your description it's not clear that you are successfully rendering the page at all. What happens when you Preview the page?
    – David Reed
    Feb 21, 2018 at 21:37
  • @DavidReed I just updated the post with an image of the page. I'm not exactly sure why it has two buttons. Feb 21, 2018 at 21:52
  • That's how page buttons render, top and bottom of the page block element. Can you show what you mean be "the markup for the page is displayed without the data"?
    – David Reed
    Feb 21, 2018 at 21:54
  • I just meant the buttons and the page section but that the actual data from the list wasn't being displayed. Feb 21, 2018 at 21:55

1 Answer 1


I am posting this as an answer because I believe this is the underlying issue based upon your screenshots and comments.

You appear to be trying to iterate over something that's not a collection (a single CampaignMember) by including an <apex:dataList> inside an <apex:repeat>. Remove the data list entirely, and use the repeat element to iterate over your list of CampaignMembers to display attributes of each one.

Additionall, you can't call Apex (System.debug) inline in Visualforce. You may use Visualforce merge tags ({! }) in the page body (i.e., not within a tag).

  • Thanks! I think that should work but it seems that the data may not be coming through. Should my method createCampaignFromPage() be returning something other than null? I wasn't sure exactly what the official way was to send data from the class to the page. The method createCampaignFromPage() is the one that actually returns the list of CampaignMember. Feb 22, 2018 at 15:05
  • You send data from class to page by populating it in class properties and referencing it with Visualforce expression syntax. Visualforce action methods return a PageReference for navigation, or null to reload the page.
    – David Reed
    Feb 22, 2018 at 15:26
  • Oh ok, I'm not sure what the problem is then. My class is non-static so would a new instance of the class need to be made in the visualforce page before it's method can be called or does the class have to be static? Feb 22, 2018 at 16:33
  • I'm sorry, I don't really follow. Can I suggest working through the Visualforce Developer Guide or some Trailheads to get a better sense of the overall structure you need to work in? It's easier to work out the trees once you have a sense of the forest, to butcher a metaphor.
    – David Reed
    Feb 22, 2018 at 16:36
  • Ok, so the issue with not seeing anything from the class method didn't have to do with whether or not the class was static but instead I just needed to add getters and setters for the attributes. I have a test variable from the class that I'm printing in the page now, but I'm still having an issue with the loop. I'm pretty sure the data is coming through though. Is there any way to check the contents of the list when the method is called to ensure that it isn't empty? I have the updated page code in the post. Feb 23, 2018 at 19:00

You must log in to answer this question.

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