loader
Enabling Article Voting For Guest user in Salesforce

Enabling Article Voting for Guest/Unauthenticated Users in Salesforce

Table of Contents

INTRODUCTION

How can We enable article voting for the guest users without prompting them to login. Salesforce lets guest users vote their own article without logging in.

SOLUTION

To allow guest users to like or dislike articles in Salesforce, you can follow these steps:

  1. Create a custom object to track article votes. This object should have fields to store the article ID, vote type (like or dislike), and any other relevant information.
  2. Enable public access to the custom object so that guest users can interact with it.
  3. Add a button or link on the article page layout to capture the guest user’s vote. This button/link should trigger an Apex controller or a Lightning component.
  4. In the Apex controller or Lightning component, write code to handle the vote submission. This code should validate if the guest user has already voted for the article to prevent multiple votes. If the user has not voted, create a new record in the custom object to store the vote information.

Here’s an example of how the code:

LWC:

HTML

LWC Controller:

JS

The Apex controller could look like:

Java

In your Lightning component or Visualforce page, call the submitVote method from the Apex controller when the guest user clicks the like or dislike button. Pass the article ID and vote type as parameters to the method.

Remember to handle any necessary error checking and provide appropriate feedback to the guest user after submitting the vote.

Note: This is a basic example, and you may need to customize it further based on your specific requirements and Salesforce implementation.


Need help to develop the LWC for guest user, please contact us here.