Skip to main content
Hello, 

I would like to create a table for one of my visualforce pages that would show the number of opportunities owned by each user.

I know how to list them, is there a simple way of counting them?

I apologize for the broad, general question - but I am staring from scratch here.

Thanks, 

John
2 件の回答
  1. 2015年11月10日 22:56
    Use aggregrateResult and count. 

     

    List<aggregateResult> opptysAR = [SELECT ownerId oid, COUNT(id) opptyCount FROM Opportunity ORDER BY ownerId GROUP BY ownerId];

    For (AggregateResult ar :opptysAR) {

    system.debug('OwnerId, count= ' + ar.get('oid') + ' ' + ar.get('opptyCount');

    }

    Not sure if that's correct on the syntax - but it would be close. 

     
0/9000