Last week our team had a fairly straightforward development task: Create a Lightning Component that calls the database and displays the Name of a different User record, among other things. Simple enough. Well, simple if you haven't enabled nickname display.
There is a feature in Communities called 'Enable nickname display' that will not allow User.Name to be displayed in a Community, even when calling it from Apex. Usually, this is for security reasons. So, in situations where a component attempts to display User.Name, it will display the Nickname instead (User.CommunityNickname).
This isn't obvious. The setting can be found by going to Setup/All Communities/Workspaces/Administration/Preferences. At the top of the Preferences page, under the General section, you will see the 'Show nicknames' checkbox. If you deselect the checkbox, your code will run as expected. You can read more about it in the Salesforce Community Documentation here: https://help.salesforce.com/articleView?id=networks_enable_nickname_display.htm&type=5.
But what if you want 'Show nicknames' selected and want to display User.Name in certain circumstances.
To get around this constraint, we updated the Apex controller class to search for the User record without sharing, and then stored the User.Name in a String variable. We then passed the String variable back to the Lightning Component's JS, resolving the problem.
The article above does not discuss how to pass the value from Apex to a custom Lightning Component. See a basic code snippet below for an example on how to do so. Happy coding!
To get started with Cloud Pacific, go here to complete a simple form. A Cloud Pacific Account Manager will collaborate with you to clarify your needs and goals, and customize a service package and roadmap that will help your business grow and thrive on Salesforce. Reach out to us here!