+ Start a Discussion
Btuitasi1Btuitasi1 

Use promote/demote buttons in visualforce

I've seen the promote/demote features on the ideas page standard object and would like to use it on my custom visualforce page which displays 2 most recent ideas and 2 most voted on. How would I add this to my custom controller and visualforce page so that users can click to promote or demote an idea?

Thanks!!

Controller so far:
public with sharing class topIdeaExt {

public List<Idea> getRecent2()
    {
        return [SELECT Id, Title, Name__c, CreatedDate, Voting_Status__c FROM Idea order by createdDate desc Limit 2];
    }
    public List<Idea> getMostVoted2()
    {
        return [SELECT Id, Title, Name__c, CreatedDate, Voting_Status__c FROM Idea order by VoteTotal desc, CreatedDate desc Limit 2];
    }
    public List<AggregateResult> getTop6Contributors()
    {
        return [SELECT CreatedById, CreatedBy.Name Name  FROM Idea group by createdbyid, CreatedBy.Name order by count(CreatedById) desc limit 6];
    }
}


ShashankShashank (Salesforce Developers) 
You can use the vf component "apex:commandButton" (http://www.salesforce.com/us/developer/docs/pages/Content/pages_compref_commandButton.htm) for the Promote/Demote. You can give the url of the button image in the image attribute, and in the action attribute, specify a method from the controller which queries and adds the vote to the idea using the "Vote" sobject (http://www.salesforce.com/developer/docs/api/Content/sforce_api_objects_vote.htm)