Skip to content

IdeaVoteComponentController

Ethan Dunzer edited this page Aug 29, 2024 · 1 revision

Overview

The IdeaVoteComponentController Apex class is focused on handling the retrieval and voting actions for a single idea within the Salesforce platform. This controller is specifically designed for the IdeaVoteComponent to provide efficient and streamlined operations.

Methods

getIdeaWithVotes

This method retrieves a single idea and the current user's vote for it.

Signature: @AuraEnabled(cacheable=true) public static IdeaWrapper getIdeaWithVotes(Id recordId)

Parameters:

  • recordId: The ID of the idea to retrieve.

Returns:

  • An IdeaWrapper object containing the idea and the associated vote.

Details:

  • Queries the Idea__c record based on the provided recordId.
  • Retrieves the vote associated with the current user for this idea.
  • Returns the idea and the vote encapsulated in an IdeaWrapper.

handleUpVote

This method manages the upvoting logic for the idea, similar to the IdeaListViewComponentController.

Signature: @AuraEnabled public static void handleUpVote(Id ideaId)

Parameters:

  • ideaId: The ID of the idea to upvote.

Details:

  • This method is a passthrough to the IdeaVotingController.handleUpVote method, managing the logic for upvoting.

handleDownVote

This method manages the downvoting logic for the idea, similar to the IdeaListViewComponentController.

Signature: @AuraEnabled public static void handleDownVote(Id ideaId)

Parameters:

  • ideaId: The ID of the idea to downvote.

Details:

  • This method is a passthrough to the IdeaVotingController.handleDownVote method, managing the logic for downvoting.

IdeaWrapper Class

A wrapper class that encapsulates an Idea__c record and its associated Idea_Vote__c record.

Fields:

  • idea: An instance of Idea__c.
  • userVote: An instance of Idea_Vote__c representing the current user's vote on the idea.

Constructor:

  • Initializes the wrapper with an idea and its associated vote.