PDI practice question 16 of 30

Which three Salesforce resources can be accessed from a Lightning web component? Choose 3 answers

Full set: 201 questions
Answer options
A: Static resources Correct answer
B: All external libraries
C: SVG resources Correct answer
D: Third-party web components
E: Content asset files Correct answer
Correct Answer:
A. Static resources; C. SVG resources; E. Content asset files
Explanation

Lightning Web Components (LWC) can access several types of Salesforce-managed resources through specific, secure mechanisms. LWCs use the @salesforce/resourceUrl scoped module to import and reference static resources, which can contain JavaScript libraries, CSS, and images. Similarly, the @salesforce/contentAssetUrl module provides a URL to content asset files, making them accessible within a component. SVG images are also directly supported; they can be included in a component's HTML template, often for icons, or loaded from a static resource. These mechanisms ensure that all assets are served through the Salesforce platform, maintaining security and performance standards.

Why Incorrect

B. All external libraries: Lightning Locker Service restricts direct access to arbitrary external libraries from CDNs for security. Libraries must be uploaded as static resources to be used.
D. Third-party web components: Generic, non-Salesforce web components cannot be used directly. Components must be built as LWCs or be part of a managed package to be composed.

References

1. Static Resources: Salesforce Lightning Web Components Developer Guide, "Access Static Resources". This section details the use of the import { resourceUrl } from 'lightning/platformResourceLoader' and the @salesforce/resourceUrl/{resourceName} scoped module to access static resources from within a component's JavaScript.

2. Content Asset Files: Salesforce Lightning Web Components Developer Guide, "Access Content Asset Files". This page explains how to use the @salesforce/contentAssetUrl/{assetName} scoped module to get the URL for a content asset file, which can then be used in templates.

3. SVG Resources: Salesforce Lightning Web Components Developer Guide, "Use SVGs". This document describes how to use SVG icons, including referencing them from the Lightning Design System (SLDS) utility icons or from static resources. It states, "To use an SVG resource, import it and use it in the template."

4. Third-Party Libraries (Refuting B): Salesforce Lightning Web Components Developer Guide, "Use Third-Party JavaScript Libraries". This guide clarifies that external libraries must be uploaded to Salesforce as static resources and are subject to the security restrictions of Lightning Locker. It does not permit access to "all" external libraries directly.

Scroll to Top