6

I need to get the Profile name in my Aura component. I am converting my JS button to a Lightning Quick Action, so I need something like this in my component:

"{!$Profile.Name}"

3 Answers 3

1

You can't use $Profile in Lightning. For that, you need to write some Apex code. Please refer to this blog post for more details.

1
  • 5
    Can you include relevant code from the link in your answer or atleast how to retrieve profile id and name from apex
    – RedDevil
    Commented May 17, 2019 at 10:34
13

It's not necessary to make an Apex call for this. You can retrieve the profile of the current user with a force:recordData component and an associated aura:attribute component, like so:

<aura:attribute name="CurrentUser" type="Object"/>
<force:recordData recordId="{!$SObjectType.CurrentUser.Id}"
                  fields="Profile.Name"
                  targetFields="{!v.CurrentUser}"/>

Then you can access that data in your component like so:

{!v.CurrentUser.Profile.Name}

And in your component controller like so:

const username = component.get('v.CurrentUser')['Profile'].Name;
2
  • I tried this approach but it did not work for me. Do I need to populate anything for CurrentUser from the previous component/provide it as an input to this component?
    – SfdcBat
    Commented Feb 10, 2022 at 17:09
  • @SfdcBat, no, there's no prerequisite for this technique. At least there wasn't in my case.
    – isherwood
    Commented Sep 14, 2023 at 14:21
2

The global value providers you are used to using in Visualforce are not available in lightning. The Lightning Aura Components developer guide further expands on this and the supported global value providers.

So, you will have to get that info from the server in Apex using a callout from your quickactions component controller.

You must log in to answer this question.

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