1

i'm trying to use custom LWC (DisplayNews) that uses apex class to gather data from salesforce org, this works fine when user is logged in but when i visit site from unlogged user i'm getting error : "You do not have access to the Apex class named 'LwcHomePageController"

any idea how to use that LWC without being logged in?

and i was actually trying to alow access for that class via public access settings but it did not solve my problem, the error was gone but site looked just as before (without pictures and everything)

do i have to use Lightning Out or is there better sulution to this?

(upper photo is lot logged in)

not logged vs logged user

1 Answer 1

6

This is because your Site Guest User Profile does not have access to the Apex Class or your Guest User profile does not have access to the object or fields or records.

In order to provide access follow the below steps

  1. Find the Sites in the settings linked to your Experience Cloud Site

enter image description here

  1. Next click on the Site record linked to Experience Cloud Site. You will notice there is one Site record for each Experience Cloud site in your org

enter image description here

  1. Navigate to public access settings via the Public access settings button as shown below to find the Guest Profile

enter image description here

  1. Assign the Apex class access to the Guest Profile.

enter image description here

Apart from all of this, I would also look into the below

  1. Make sure the Guest user Profile has Read access to the objects used in the query.
  2. Make Sure the Guest User profile has Read access to the fields in the Query.
  3. Make sure the Guest user Profile has access to the records (Via Guest user Sharing rules)

For some reason if you want to run the SOQL in your apex in System Context without checking record access, then set the Security context of the class using without sharing.

3
  • as i said, i have tried this, mentioned error will go away but page looks still the same (it did not load anything) : imgur.com/a/0560Q4v Jan 29, 2022 at 20:29
  • Is your apex class without sharing mode?With out looking at code and your org object security it’s hard to tell what’s causing it. Jan 29, 2022 at 20:31
  • Does the site user has access to the records? Does the site user has access to the fields used in the query? Does the site user has access to the object? Is your apex class declared without sharing or uses with sharing? Jan 29, 2022 at 20:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .