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
Btuitasi1Btuitasi1 

How to display number of record entries per user

I have a visualforce page that acts as a leaderboard for users. I would like the ability to show how many submissions a user has for the Idea sObject and how many times he/she has voted on any idea. How would I develop this in my custom controller?

Thanks!
pconpcon
You should be able to do a Aggregate query to obtain this.  If you want to get the number of votes a specific user has given:
 
select count(ParentId)
from Vote
where CreatedById = 'xxxxxxx'
     Parent.Type = 'yyyyyyyy'

where 'xxxxxx' is the user's id (in your controller you can use Userinfo.getUserId() to get the current user's Id and where 'yyyyyyyy' is the RecordTypeId of the Ideas you want to count


If you want to do more of a leaderboard style thing you could get the top 10 most voting users
 
select count(ParentId),
     CreatedById
from Vote
where Parent.Type = 'yyyyyyyy'
group by CreatedById
order by count(ParentId)
desc limit 10

where 'yyyyyyyy' is the RecordTypeId of the Ideas you want to count

Unfortunately there is an Implementation restriction on querying the Vote object that it must be filtered by either ParentId, Parent.Type or Id
Btuitasi1Btuitasi1
​Thanks for the feedback!

Where would I find the RecordTypeID of the ideas I want to count? 
 
pconpcon
You can query your record types with
 
select Id,
     Name,
     DeveloperName
from RecordType
where IsActive = true

I think you may have to use Parent.RecordTypeId instead of Type, but I may be wrong.  I've never used the Idea or Vote object