0

I'm using the standard idea object to post ideas and have users promote/demote ideas. How can you query an idea record to determine if a user has voted on the idea?

Thanks for any help.

2 Answers 2

3

You can use the Vote sObject. Your query might look something like this:

List<Vote> userVote = [SELECT CreatedById, ParentId FROM Vote WHERE CreatedById = :UserId AND ParentId = :IdeaId]

obviously replacing the Ids appropriately in the where clause. You could then check if this list's size is 0 or not to determine if a given user voted.

4
  • your query is not correct.
    – Ankuli
    Feb 25, 2015 at 5:25
  • Fixed. The query was written as borderline pseudocode as I didn't check if it was syntactically correct. I presume the OP understood the gist of what I was suggesting
    – kbentsen
    Feb 25, 2015 at 5:53
  • Is there a way to just get all Votes for a given user id?
    – Coova
    Aug 22, 2016 at 14:38
  • Just remove the "AND ParentId = :IdeaId" part of the where clause
    – kbentsen
    Aug 23, 2016 at 19:12
0

List<Vote> lstVote = [SELECT Type FROM Vote WHERE CreatedById =: UserId AND ParentId =: IdeaId];

This query will work , what is asked in question.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .