I have a HTML button:

<a class="btn-lg btn-data" role="button">Vote Up</a> <a class="btn-lg btn-data"  role="button">Vote Down</a>

I also have two number fields (Vote_Up__c and Vote_Down__c) in my custom object that, when clicked, needs to be increased by 1 when a user clicks the Vote Up or Vote Down button in my visualforce page. Additionally, I don't want the same user to be able to "vote" twice on the same record.

Any ideas on how to implement this in an extension?



Easy, first of all you'll need a custom object to store your current vote count. This is used for both getting your tally of votes plus knowing if your current user has already voted.

Custom Object will need at least the following fields:

Voter__c     => Lookup to User table

Idea__c      => Lookup to custom table which is about the idea

WayOfVote__c => Your choice, Boolean or Text field. (I rather not go boolean because if its a bad input you can't really tell if they voted for/against or just bad data.

Then you just make your query to see how the vote swing went.

Also should have a query to see if your current user has already voted and you can make your vote button a different color to show that they already voted, such as:

  • Green for Yes / Up arrow
  • Red for No / Down arrow
  • Dark Grey for the option of voting
  • Light Grey for having disabled voting options.

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.