0

In an effort to retrieve the current user in JavaScript on a Salesforce page, I came across this command:

$A.get("$SObjectType.CurrentUser")

This is great because it works. What's not great is that I have no idea what it means.

I'm looking for one or more of the following:

  • What does each part of the command mean?
  • Is there documentation I read about this? (I don't know what to call it, so am having a hard time searching for it)
  • What other types of values can I search for with this? It would be great if I could retrieve other objects on the page.

So far I've been able to figure out that $A appears to be a namespace for Aura, which I've found limited documentation at /auradocs/reference.app#reference?topic=api:$A. It includes the methods that can be called, but I don't know what parameters are available.

When looking at the JavaScript on the page it also looks like the "values" that can be used include: CurrentUser, userLocaleLang, containerVersion, communityPrefix, eswConfigDeveloperName, LightningRichTextButton.

1 Answer 1

2

In general, these are known as Value Providers. Unfortunately, $SObjectType is not officially documented. While it does work, there's no way to know what else you can do with it except to play with it.

What does each part of the command mean?

$A is the Aura runtime. It contains methods and classes useful for using Aura. It's documented in various pages starting here.

.get is a function that accepts a string and returns a value. You can use this to get values from global value providers (above), application events, and "more." This is probably another great failing of Aura, as it's not entirely clear if there's one place you can go to find all possible values for this method.

$SObjectType.CurrentUser is just a String. The first half, $SObjectType, is a value provider, much like $Label or $Browser (see earlier link). CurrentUser is a value that $SObjectType provides. It loads automatically and provides context for the current user. It may be undefined for Guest users and other anonymous access types.

Is there documentation I read about this? (I don't know what to call it, so am having a hard time searching for it)

As stated above, there is the JavaScript reference guide, and the Value Providers page. Other documentation (e.g. the page on Application Events) covers other specific uses of $A.get.

What other types of values can I search for with this? It would be great if I could retrieve other objects on the page.

Basically, as far as I know, Application Events, labels, and the special Value Providers.

In general, the only stable values you should use with $A.get should be documented. This can include $A.get("e.namespace:eventName") (application events), and various $A.get("$ValueProvider") entries that are documented. One of the more useful options is $Label, which can get translated custom labels in the user's language automatically.

You must log in to answer this question.

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