+ Start a Discussion
Patricia Boyce 6Patricia Boyce 6 

The example in Trailhead Using Standard List Controller doesn't work

It's the example in the Trail:
<apex:page standardController="Contact" recordSetVar="contacts">
02    <apex:pageBlock title="Contacts List">
03         
04        <!-- Contacts List -->
05        <apex:pageBlockTable value="{! contacts }" var="ct">
06            <apex:column value="{! ct.FirstName }"/>
07            <apex:column value="{! ct.LastName }"/>
08            <apex:column value="{! ct.Email }"/>
09            <apex:column value="{! ct.Account.Name }"/>
10        </apex:pageBlockTable>
11         
12    </apex:pageBlock>
13</apex:page>

First I entered it all by hand and it goes to a page with the title but no columns nor data. So I just copied their example and pasted it, still no data on the page, nor headlines, columns, etc. 
What is missing?
Thanks
Deepak GulianDeepak Gulian
Nothing is missing can you please share a screenshot of you VF page Code.
Patricia Boyce 6Patricia Boyce 6
[image: Inline image 1] That's mine. Looks like their's I think.
Deepak GulianDeepak Gulian
I can't see any image
Vishwajeet kumarVishwajeet kumar
Looks you have custom contacts created in org and standard qurey is not able to get contact.

Try this :

Controller:
public class ContactList2Con {
    // ApexPages.StandardSetController must be instantiated
    // for standard list controllers
    public ApexPages.StandardSetController setCon {
        get {
            if(setCon == null) {
                setCon = new ApexPages.StandardSetController(Database.getQueryLocator(
                    [SELECT FirstName ,LastName, Email ,Account.Name FROM Contact]));
            }
            return setCon;
        }
        set;
    }

    // Initialize setCon and return a list of records
    public List<Contact> getContacts() {
        return (List<Contact>) setCon.getRecords();
    }
}

Page:
 
<apex:page Controller="ContactList2Con" >
    <apex:pageBlock title="Contacts List">
        
        <!-- Contacts List -->
        <apex:pageBlockTable value="{! contacts }" var="ct">
            <apex:column value="{! ct.FirstName }"/>
            <apex:column value="{! ct.LastName }"/>
            <apex:column value="{! ct.Email }"/>
            <apex:column value="{! ct.Account.Name }"/>
        </apex:pageBlockTable>
        
    </apex:pageBlock>
</apex:page>

 
Patricia Boyce 6Patricia Boyce 6
Thank you. I was trying to do it just as they showed. You're saying it's not the code, but rather something in my org? I can try your code, but to get it to do as they show, do I need to dismember something in the org? I surely don't mind learning something new, but I assumed that since this is a beginning exercise, I could just follow their standard. What is likely my problem? Patricia
Deepak GulianDeepak Gulian
That was standardcontroller and it should display the contact list, there is nothing wrong in your code.Can you please share screenshot of VF page
<apex:page standardController="Contact" recordSetVar="contacts">
    <apex:pageBlock title="Contacts List">
         
        <!-- Contacts List -->
        <apex:pageBlockTable value="{!contacts}" var="ct">
            <apex:column value="{!ct.FirstName}"/>
            <apex:column value="{!ct.LastName}"/>
            <apex:column value="{!ct.Email}"/>
           <apex:column value="{!ct.Account.Name}"/>
        </apex:pageBlockTable>
         
    </apex:pageBlock>
</apex:page>

 
Patricia Boyce 6Patricia Boyce 6
User-added image
Thanks
Deepak GulianDeepak Gulian
Is there any records in your contact object ?
Patricia Boyce 6Patricia Boyce 6
It's a dev org. There are 65 contacts.
Patricia Boyce 6Patricia Boyce 6
Here's the second part of their demo. It gives me nothing but a visualforce error
Visualforce Error
Help for this Page
Invalid selectOptions found. Use SelectOption type in Apex.

User-added image
This is really puzzling. If my code is right (copied from their example, does that mean there is a problem in my org?
Deepak GulianDeepak Gulian
Clear Cache If this wont work then Just do logout from your developer org. and try to login again
1. Click on set up
2. Left Section Quick Search Box (Type : Visualforce Page)
3. Click on link Visual force page.
4. Now find your page now in available list of pages.
5. Open that page and click Preview button.

Your Url should be
YourORG_URL/apex/ContactList
Amit Chaudhary 8Amit Chaudhary 8
Hi ,

Your code look good and working for me also
<apex:page standardController="Contact" recordSetVar="contacts">
    <apex:form>

        <apex:pageBlock title="Contacts List" id="contacts_list">
        
            Filter: 
            <apex:selectList value="{! filterId }" size="1">
                <apex:selectOptions value="{! listViewOptions }"/>
                <apex:actionSupport event="onchange" reRender="contacts_list"/>
            </apex:selectList>

            <!-- Contacts List -->
            <apex:pageBlockTable value="{! contacts }" var="ct">
                <apex:column value="{! ct.FirstName }"/>
                <apex:column value="{! ct.LastName }"/>
                <apex:column value="{! ct.Email }"/>
                <apex:column value="{! ct.Account.Name }"/>
            </apex:pageBlockTable>
            
        </apex:pageBlock>

    </apex:form>
</apex:page>
Just copy paste same code and save. Then click on Preview button Like below screen shot.

User-added image

Output will be like below :-
User-added image

Let us know if this will help you

Thanks
Amit Chaudhary

 
Tim TerryTim Terry
I'm also having the same issue with this section of the visualforce training.  I'm using my dev org and confirmed that contacts exist, however, the example code produces an empty list.   Has anyone found a fix to this?

 I read above that maybe a custom contact could be causing an issue.  how would I identify that? 

--Tim
INDERJEET S SINGERKHANIINDERJEET S SINGERKHANI
<apex:page standardController="Contact" recordSetVar="Contacts">
    <apex:form>

        <apex:pageBlock title="Contacts List" id="contacts_list">
        
            Filter: 
            <apex:selectList value="{! filterId }" size="1">
                <apex:selectOptions value="{! listViewOptions }"/>
                <apex:actionSupport event="onchange" reRender="contacts_list"/>
            </apex:selectList>

            <!-- Contacts List -->
            <apex:pageBlockTable value="{! Contacts }" var="contact">
                <apex:column value="{! contact.FirstName }"/>
                <apex:column value="{! contact.LastName }"/>
                <apex:column value="{! contact.Email }"/>
                <apex:column value="{! contact.Account.Name }"/>
            </apex:pageBlockTable>
            
        </apex:pageBlock>

    </apex:form>
</apex:page>
Hello Everyone,
I got the same issue, but changing few keywords giving me a bit of change like getting field names. I try almost everything of my knowledge so far and get changes from my first screen shot to second.
Please help me to solve this issue as it will give me trouble in later examples.
Screenshot1:
screenshot1
Screenshot2:
Screenshot2
 
INDERJEET S SINGERKHANIINDERJEET S SINGERKHANI
Hello Everyone,
I use the same code for different sObject like account and it works. It must be some issue with retrieving Contact records. Thank you all...!
chris tan 10chris tan 10
Hi Guys, 

I've figured out the issue. The code is correct provided by trailhead.

You will need to open 2 tabs.

First tab will be at your original contacts screen.
Second tab will be your visualforce page (contactlist)

On the first tab, toggle the view to "All Contacts". Once done, switch to your second tab, refresh the page. You will see all your contacts populated by the visualforce page that you created.
Keval Shah 2Keval Shah 2
Hey Chris, Thanks for posting the solution. Although the solution sounds crazy but it worked for me. Any idea why we need to do this to make it work? 
Immam Asain KuthbudeenImmam Asain Kuthbudeen
HI All,

I think, this behavior is cos the default view taken by the Preview page doesn’t not have any record to show (may New Last Week/New This Week).
When we change the view to All Records in another tab and refresh the Preview page we can see the Records!
 
It can be verified by switching different views and refreshing the Preview page, the record count changing accordingly!!!
 
James DowellJames Dowell
Worked for me, Chris. Thanks!!!
Jasvinder Singh 8Jasvinder Singh 8
Chris ..thanks a lot. I was having the same problem and couldnt figure out the reason. Great job Chris
Nazrul AminNazrul Amin
Thanks @Chris, this helped me resolve a different Trailhead challenge ! :)