@salesforce Modules

Modules scoped with @salesforce add functionality to Lightning web components at runtime.

Modules that are imported without @salesforce, like lightning/uiRecordApi, contain resources that don't change and are universal to all orgs.

Some modules have a fixed set of module identifiers. For example, the @salesforce/i18n module supports many identifiers including @salesforce/i18n/dir and @salesforce/i18n/lang.

Some modules have a dynamic set of module identifiers. The set is defined by the organization’s metadata. For example, @salesforce/schema accesses an organization’s objects and fields.

Import Apex methods from @salesforce/apex. The imported methods are functions that the component can call either via @wire or imperatively. See Call Apex Methods.

  • apexMethodName—A symbol that identifies the Apex method.
  • apexMethodReference—The name of the Apex method to import.
  • Classname—The name of the Apex class.
  • Namespace—The namespace of the Salesforce organization. Specify a namespace unless the organization uses the default namespace (c), in which case don’t specify it.
  • apexMethodParams—An object with properties that match the parameters of the apexMethod, if needed. If a parameter value is null, the method is called. If a parameter value is undefined, the method isn’t called. If the Apex method is overloaded, the choice of what method to call is non-deterministic (effectively random), and the parameters passed may cause errors now or in the future. Don't overload @AuraEnabled Apex methods.

apexMethodParams is an object. To pass parameter values to an Apex method, pass an object whose properties match the parameters of the Apex method. For example, if the Apex method takes a string parameter, don’t pass a string directly. Instead, pass an object that contains a property whose value is a string.

propertyOrFunction—A private property or function that receives the stream of data from the wire service. If a property is decorated with @wire, the results are returned to the property’s data property or error property. If a function is decorated with @wire, the results are returned in an object with a data property or an error property.

The data property and the error property are hardcoded values in the API. You must use these values.

Import getSObjectValue from @salesforce/apex. Call this method to get a field value from an object retrieved from an Apex method.

  • sObject—The object returned by the Apex method.

  • fieldApiName—The API name of the field. The value can be either a string or reference to a field imported from @salesforce/schema. You can specify up to 5 levels of spanning fields. For example, Opportunity.Account.CreatedBy.LastModifiedById returns 4 levels of spanning fields.

Import refreshApex from @salesforce/apex. Call this method to query the server for updated data returned by Apex, and refresh the cache of a wired property.

The use of refreshApex to refresh data from non-Apex wire adapters is deprecated. To refresh record data returned by a non-Apex wire adapter, use notifyRecordUpdateAvailable(recordIds) instead.

  • Where {valueProvisionedByApexWireService} is either a property annotated with an Apex @wire, or if you annotated a function, the argument that the wired function receives.

To update a record via imperative Apex, call the Apex method and then call notifyRecordUpdateAvailable() to update the cache. The refreshApex() function doesn’t refresh data that was fetched by calling an Apex method imperatively.

Import Apex methods from @salesforce/apexContinuation.

  • apexMethodName—A symbol that identifies the Apex method.
  • apexMethodReference—The name of the Apex method to import.
  • Classname—The name of the Apex class.
  • Namespace—If the class is in the same namespace as the component, don’t specify a namespace. If the class is in a managed package, specify the namespace of the managed package.

See Make Long-Running Callouts with Continuations.

  • formFactorPropertyName—A name that refers to the form factor of the hardware running the browser. Possible values are:
    • Large—A desktop client.
    • Medium—A tablet client.
    • Small—A phone client.

Pass the form factor to the getRecordCreateDefaults wire adapter to get the default layout information and object information for creating a record.

Import the network ID of the current Experience Builder site from @salesforce/community/Id.

Import the base URL of your Experience Builder site from @salesforce/community/basePath.

The base path is the section of the site’s URL that comes after the domain. So if your site domain name is UniversalTelco.force.com and myPartnerSite was the URL value added when you created the site, the community’s URL is UniversalTelco.force.com/myPartnerSite/s. In this case, myPartnerSite/s is the base path.

See Get Information About the Current Experience Builder Site.

If a component imports @salesforce/community, it can target only an Experience Builder page. The component can’t be used in any other Salesforce container. See Configure a Component for Experience Builder.

Import content asset files from @salesforce/contentAssetUrl.

  • myContentAsset—A name that refers to the asset file.

  • contentAssetReference—The name of the asset file.

    An asset file name can contain only underscores and alphanumeric characters, and must be unique in your org. It must begin with a letter, not include spaces, not end with an underscore, and not contain two consecutive underscores.

  • namespace—If the asset file is in a managed package, this value is the namespace of the managed package.

See Access Content Asset Files.

Import internationalization properties from @salesforce/i18n.

  • internationalizationPropertyName—A symbol that identifies the internationalization property.

  • internationalizationProperty—An internationalization property.

The internationalization properties are listed in Access Internationalization Properties.

Import labels in your Salesforce organization from @salesforce/label.

  • labelName—A name that refers to the label.
  • labelReference—The name of the label in your org in the format namespace.labelName. We use this format because it’s the same format used in managed packages, in Visualforce, and in other Salesforce technologies. You can use the same format to access labels, myns.labelName, regardless of where you’re accessing them.

See Access Labels.

Import a Lightning message channel that a component can use to communicate via the Lightning Message Service.

  • channelName—A symbol that identifies the message channel.

  • channelReference—The API name of the message channel.

  • namespace—If the message channel is in a managed package, this value is the namespace of the managed package. If the message channel is not in a managed package, do not include a namespace.

See Create a Message Channel

Import static resources in your Salesforce organization from @salesforce/resourceUrl.

  • myResource—A name that refers to the static resource.

  • resourceReference—The name of the static resource.

    A static resource name can contain only underscores and alphanumeric characters, and must be unique in your org. It must begin with a letter, not include spaces, not end with an underscore, and not contain two consecutive underscores.

  • namespace—If the static resource is in a managed package, this value is the namespace of the managed package.

See Access Static Resources.

Import references to Salesforce objects and fields from @salesforce/schema.

  • objectName—A symbol that identifies the Salesforce object.
  • objectReference—The name of a Salesforce object.
  • fieldName—An imported symbol that identifies the Salesforce field.
  • fieldReference—The name of a Salesforce field. You can specify up to 5 levels of spanning fields. For example, Account.Owner.Name returns 3 levels of spanning fields.
  • namespace—If the object or field is in a managed package, this value is the namespace of the managed package.

See Import References to Salesforce Objects and Fields.

Import the site ID of the current Experience Builder site from @salesforce/site/Id.

Import the list of active languages in your Experience Builder site from @salesforce/site/activeLanguages.

The list of active languages in your Experience Builder site includes metadata on the default site language and all other active languages. You can configure a site’s languages in Experience Builder in Settings | Languages. Inactive languages are excluded from the list. The return value is an array of language objects, where each object includes the language’s label and the code, such as en-US. The array is sorted alphabetically by the label.

See Get Information About the Current Experience Builder Site.

If a component imports @salesforce/community or @salesforce/site, it can target only an Experience Builder page. You can’t use the component in any other Salesforce container. See Configure a Component for Experience Builder.

Import the current user’s ID from @salesforce/user/Id.

userId—An imported symbol that identifies the Salesforce user ID.

To determine whether the user is a guest user, import the current user’s status from @salesforce/user/isGuest.

isGuestUser—A symbol that identifies whether the user is a guest user (true) or not (false).

See Get Information About the Current User.

Import a permission and check whether it’s assigned to the current user.

  • hasPermission—A boolean indicating whether the current user has the imported permission (true) or not (undefined).

  • Permission—The name of a Salesforce user permission.

See Check Permissions.

Import a custom permission and check whether it’s assigned to the current user.

  • hasPermission—A boolean indicating whether the current user has the imported permission (true) or not (undefined).

  • Permission—The name of a Salesforce custom permission.

See Check Permissions.