Inserting Vote:

    vote v=new Vote();
    v.parentId='0875w000000QYlZ'; //passing Idea Id
     insert v;


System.DmlException: Insert failed. First exception on row 0; first error: DUPLICATE_VALUE, duplicate value found: duplicates value on record with id: : []

Q2; How to user query upcount and down count of the Idea. In which object details it resides?

In idea level,can able to see vote total and vote score not upcount and downcount


Hey @Annappa PH it looks like it's because that user (the running user presumably) has already voted on that idea. If this is a unit test you'd likely need to create another user and do a System.runAs(newUser).

If this is live logic, you'd need to first do a query to check if the user has already voted: [query to determine if someone has voted on an idea

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

For your second question, you could also just use the same query, adding the Type field to your query to indicate up or down. Or to your point if you want it on Idea level, utilize the VoteScore field on an Idea soql query.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.