function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Andrew FandreAndrew Fandre 

Apex Controller throws error when not logged in.

I have posted this on salesforce stack exchange (https://salesforce.stackexchange.com/questions/317374/forgot-username-lwc-controller-throws-error-outside-community) but I thought I'd post it here as well.

My forgot username Aura component works when I'm logged in, but when I'm not logged in, the Apex controller Errors out. How do I get this global component to work when not logged in?
ShirishaShirisha (Salesforce Developers) 

Hi Andrew,

Greetings!

Can you please provide the error message that you get as I haven't found any error provided on the Stack exchange as well.

Also,I would suggest you to check the access level for that Apex class for the guest user profile due to which you might not be able to access the class as guest user on the community.

Reference:https://help.salesforce.com/apex/HTViewHelpDoc?id=users_profiles_apex_access.htm#:~:text=From%20Setup%2C%20enter%20Profiles%20in,Classes%20list%20and%20click%20Add.

Kindly mark it as best answer if it helps so that it can help others in the future.

Warm Regards,
Shirisha Pathuri
 

Andrew FandreAndrew Fandre
Shrisha,

Thank you for your answer. This is definitely the problem, as I debugged the response and the error message was You do not have access to the Apex class named 'ForgotUsernameController'

Do you know what profile is used when you're not logged in on the community?

Thank you,

Andrew
 
ShirishaShirisha (Salesforce Developers) 
Hi Andrew,

Please follow the below steps to find the guest user profile:

<<Go to Setup>search for sites in the Quick find box>Click on sites>Click on the community name in the list
>>Once,you are on the community setup page then click on the "Public Access settings" button
>>Then you will be able to redirected to the Guest user profile and you can provide the apex class access as given in the link.

Thank you!