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
eriktowneriktown 

Need help displaying a user's contacts

 

Hello folks. I'm doing something which I thought was fairly straightforward, but maybe not. :)
I'm trying to create a custom page which will display the current user's contacts and allow the user to click on a button to perform an operation on that user. However, I've ran into trouble rather early on - I can't get the contact list to display at all!
I'm working from the example here:
And here is my code:
<apex:page standardController="Contact" recordSetVar="contacts" tabStyle="Contact">
    <apex:form >
        <apex:pageBlock title="Purchase" mode="edit">
            <apex:pageMessages />
            <apex:pageBlockTable value="{!selected}" var="contact">
                <apex:column value="{!contact.Name}"/>
                <apex:column headerValue="Email">
                    <apex:inputField value="{!contact.email}"/>
                </apex:column>
                <apex:column headerValue="Purchase">
                    <apex:commandButton value="Purchase"/>
                </apex:column>
            </apex:pageBlockTable>      
        </apex:pageBlock>
    </apex:form>
    </apex:page>

 

Does anyone know what I am doing wrong?
Thanks!

 

Best Answer chosen by Admin (Salesforce Developers) 
sfdcfoxsfdcfox

I assume you meant to iterate over contacts, instead. Here's my revision:

 

 

<apex:page standardController="Contact" recordSetVar="contacts" tabStyle="Contact">
    <apex:form >
        <apex:pageBlock title="Purchase" mode="edit">
            <apex:pageMessages />
            <apex:pageBlockTable value="{!contacts}" var="contact">
                <apex:column value="{!contact.Name}"/>
                <apex:column headerValue="Email">
                    <apex:inputField value="{!contact.email}"/>
                </apex:column>
                <apex:column headerValue="Purchase">
                    <apex:commandButton value="Purchase"/>
                </apex:column>
            </apex:pageBlockTable>      
        </apex:pageBlock>
    </apex:form>
    </apex:page>

 The bit in red text is my contribution to your problem.

 

All Answers

sfdcfoxsfdcfox

I assume you meant to iterate over contacts, instead. Here's my revision:

 

 

<apex:page standardController="Contact" recordSetVar="contacts" tabStyle="Contact">
    <apex:form >
        <apex:pageBlock title="Purchase" mode="edit">
            <apex:pageMessages />
            <apex:pageBlockTable value="{!contacts}" var="contact">
                <apex:column value="{!contact.Name}"/>
                <apex:column headerValue="Email">
                    <apex:inputField value="{!contact.email}"/>
                </apex:column>
                <apex:column headerValue="Purchase">
                    <apex:commandButton value="Purchase"/>
                </apex:column>
            </apex:pageBlockTable>      
        </apex:pageBlock>
    </apex:form>
    </apex:page>

 The bit in red text is my contribution to your problem.

 

This was selected as the best answer
eriktowneriktown

You're exactly right. How did I miss that!