+ Start a Discussion

How do I display Opportunities by User?

I want to display something like this:

  • User 1:
    • Opportunity 1
    • Opportunity 2
  • User 2:
    • Opportunity 3
    • Opportunity 4

Here is the Page code I'm trying to use:

<apex:page controller="myController">
<apex:pageBlock title="Opportunities by User">
<apex:dataList value="{!users}" var="user">
<apex:pageBlockSection title="{!user.firstname}">
<apex:dataTable value="{!XXX what do I put here? XXX}" var="opp">
<apex:column >{!opp.name}</apex:column>

Here is the Controller Code:

public class myController {

public List getUsers() {
return [select firstname from user];

public List getOppsForUser(User user) { // How can I use this method?
return [select name from opportunity where ownerid=:user.id];

I found my answer in this thread