-
Notifications
You must be signed in to change notification settings - Fork 1
IdeaListViewComponentController
The IdeaListViewComponentController Apex class is designed to handle the retrieval and manipulation of ideas within the Salesforce platform. It supports complex operations such as pagination, sorting, and voting, providing the necessary backend logic for the IdeaListViewComponent.
This method retrieves a list of ideas along with their associated votes for display in the IdeaListViewComponent.
Signature:
@AuraEnabled(cacheable=true)
public static Map<String, Object> getIdeasWithVotes(String sourceType, String sortField, String sortOrder, String statusFilter, Id recordId, Integer pageSize, Integer pageNumber)
Parameters:
-
sourceType
: A string representing the source of ideas (e.g., 'All', 'CurrentUser'). -
sortField
: A string indicating the field by which the results should be sorted. -
sortOrder
: A string representing the order of sorting ('ASC' or 'DESC'). -
statusFilter
: A string to filter ideas by their status (e.g., 'Active'). -
recordId
: The ID of a specific record if needed. -
pageSize
: The number of records to display per page. -
pageNumber
: The current page number for pagination.
Returns:
A map containing:
- ideas: A list of IdeaWrapper objects, each representing an idea and its associated vote.
- totalRecords: The total number of ideas found.
Details:
- Constructs a dynamic SOQL query based on the provided filters and sorts.
- Handles pagination by calculating the appropriate offset and limit.
- Collects and maps votes for each idea based on the current user's interaction.
- Returns the list of ideas and the total record count for pagination purposes.
This method manages the upvoting logic for an idea.
Signature:
@AuraEnabled
public static void handleUpVote(Id ideaId)
Parameters:
-
ideaId
: The ID of the idea to upvote.
Details:
Checks if the user has already upvoted the idea.
- If yes, removes the upvote.
- If no, adds an upvote or changes an existing downvote to an upvote.
This method manages the downvoting logic for an idea.
Signature:
@AuraEnabled
public static void handleDownVote(Id ideaId)
Parameters:
-
ideaId
: The ID of the idea to downvote.
Details:
Checks if the user has already downvoted the idea.
If yes, removes the downvote. If no, adds a downvote or changes an existing upvote to a downvote.
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.