Which two characteristics are true for Lightning Web Component custom events? (Choose 2 answers)
A. Data may be passed In the payload of a custom event using a wire decorated properties.
B. By default a custom event only propagates to its immediate container and to its immediate child component.
C. By default a custom event only propagates to it's immediate container.
D. Data may be passed in the payload of a custom event using a property called detail.
đ Explanation:
â
C. By default a custom event only propagates to its immediate container.
In Lightning Web Components (LWC), custom events are composed by default, which means they bubble up through the component containment hierarchy (i.e., parent to grandparent).
However, unless explicitly marked as bubbles: true and composed: true, a custom event will only propagate to its immediate parent (container).
So this statement is true with respect to the default propagation behavior.
đš Reference:
LWC Developer Guide â CustomEvent
â
D. Data may be passed in the payload of a custom event using a property called detail.
When dispatching a custom event, the detail property is used to pass data.
this.dispatchEvent(new CustomEvent('mycustomevent', {
detail: { message: 'Hello from child' }
}));
This detail object can then be accessed in the event handler of the listening component.
đš Reference:
LWC Dev Guide â Communicate with Events
â Why the others are incorrect:
A. Data may be passed in the payload of a custom event using a wire decorated properties.
Incorrect. @wire is used for data provisioning from Apex or LDS, not for passing event data.
Events and wire decorators serve entirely different purposes.
B. By default a custom event only propagates to its immediate container and to its immediate child component.
Incorrect. Events do not propagate down the component tree (child components). They bubble up only (to parents), and only when configured to do so.
Universal Containers has developed custom Apex code and Lightning Components in a Sandbox environment. They need to deploy the code and associated configurations to the Production environment.
What is the recommended process for deploying the code and configurations to
Production?
A. Use a change set to deploy the Apex code and Lightning Components.
B. Use the Force.com IDE to deploy the Apex code and Lightning Components.
C. Use the Ant Migration Tool to deploy the Apex code and Lightning Components.
D. Use Salesforce CLI to deploy the Apex code and Lightning Components.
Explanation:
Change Sets are the recommended and declarative way to migrate metadata (including Apex classes, triggers, Lightning Components, and configurations) from a Sandbox to Production when both environments are connected via Salesforce Deployment Connections.
Which annotation should a developer use on an Apex method to make it available to be wired to a property in a Lightning web component?
A. @RemoteAction
B. @AureEnabled
C. @AureEnabled (cacheable=true)
D. @RemoteAction(|cacheable=true)
Explanation:
To make an Apex method available to be wired to a property in a Lightning Web Component (LWC), the method must be annotated with @AuraEnabled (cacheable=true). Hereâs a detailed breakdown:
Why @AuraEnabled (cacheable=true)?
In Lightning Web Components, the @wire decorator is used to call Apex methods to fetch data reactively. For an Apex method to be compatible with @wire, it must be annotated with @AuraEnabled to expose it to Lightning components, and the cacheable=true attribute ensures the methodâs results can be cached for better performance, which is a requirement for wired methods in LWC.
The cacheable=true setting ensures the method is idempotent (does not modify data) and allows the Lightning Data Service to cache the results, reducing server calls.
Example:
public class MyApexController {
@AuraEnabled(cacheable=true)
public static List
return [SELECT Id, Name FROM Account LIMIT 10];
}
}
In LWC, this method can be wired like:
import { LightningElement, wire } from 'lwc';
import getAccounts from '@salesforce/apex/MyApexController.getAccounts';
export default class MyComponent extends LightningElement {
@wire(getAccounts) accounts;
}
Why not the other options?
A. @RemoteAction:
The @RemoteAction annotation is used in Visualforce to expose Apex methods to JavaScript remoting, not for Lightning Web Components. Itâs not compatible with LWCâs @wire functionality.
Example usage (for Visualforce, not LWC):
global class MyController {
@RemoteAction
global static String getData() { return 'data'; }
}
This is irrelevant for LWC wiring.
B. @AureEnabled:
While @AuraEnabled (without cacheable=true) exposes an Apex method to Lightning components (both Aura and LWC), itâs not sufficient for @wire in LWC. Wired methods require cacheable=true to ensure performance optimization and compatibility with the Lightning Data Service.
Methods with @AuraEnabled (without cacheable=true) can be called imperatively in LWC but not wired.
Example:
@AuraEnabled
public static void updateRecord(String recordId) { /* logic */ }
This can be called imperatively but not wired.
D. @RemoteAction(|cacheable=true):
This is not a valid annotation syntax in Apex. The @RemoteAction annotation does not support a cacheable parameter, and the syntax with a pipe (|) is incorrect. This option is a distractor and not applicable.
Key Considerations:
For @wire in LWC, the Apex method must:
Be public or global.
Be static.
Use @AuraEnabled(cacheable=true).
Not modify data (e.g., no DML operations like insert, update, or delete).
If the method needs to perform DML or other non-cacheable operations, it should use @AuraEnabled (without cacheable=true) and be called imperatively, not wired.
Reference:
Salesforce Documentation:
Call Apex Methods from Lightning Web Components: Explains the use of @AuraEnabled(cacheable=true) for wired methods.
Lightning Web Components Developer Guide: Details on @wire and Apex integration.
Trailhead:
Apex Integration with Lightning Web Components: Covers Apex method exposure for LWC.
A custom picklist field, Food_Preference c, exist on a custom object. The picklist contains the following options: 'Vegan','Kosher','No Preference'. The developer must ensure a value is populated every time a record is created or updated. What is the most efficient way to ensure a value is selected every time a record is saved?
A. Set "Use the first value in the list as the default value" as True.
B. Set a validation rule to enforce a value is selected.
C. Mark the field as Required on the field definition.
D. Mark the field as Required on the object's page layout.
Explanation:
To ensure that a picklist field always has a value when a record is created or updated, the most efficient and enforceable approach is to:
â
C. Mark the field as Required on the field definition
Setting a field as required at the field level (schema definition) ensures that no record can be saved (via API, Apex, UI, Flow, etc.) unless the field has a value.
This enforcement is universal â meaning it applies across all entry points.
This is the most efficient and robust method.
đš Reference: Salesforce Help: Make a Custom Field Required
â Why the others are incorrect or less ideal:
A. Set "Use the first value in the list as the default value" as True
This only sets a default value, but users or processes can still clear or override it.
It does not enforce that a value must be selected during record creation or update.
B. Set a validation rule to enforce a value is selected
This can work, but is less efficient than using the built-in "required" flag.
Also, it's additional configuration and logic that is unnecessary when a simpler declarative option (field-level required) exists.
D. Mark the field as Required on the object's page layout
This only makes the field required in the UI and only on that specific layout.
It does not enforce the requirement via API, Apex, Flow, or even other layouts.
Universal Container is building a recruiting app with an Applicant object that stores information about an individual person that represents a job. Each application may apply for more than one job.
What should a developer implement to represent that an applicant has applied for a job?
A. Master-detail field from Applicant to Job
B. Formula field on Applicant that references Job
C. Junction object between Applicant and Job
D. Lookup field from Applicant to Job
Explanation:
Scenario Analysis:
Applicant (a person) can apply for multiple Jobs.
A Job can have multiple Applicants.
This is a many-to-many relationship, which in Salesforce requires a junction object.
Why a Junction Object?
A junction object (e.g., "Job Application") sits between Applicant and Job with two master-detail or lookup fields:
. One to Applicant
. One to Job
This allows tracking which applicants applied for which jobs.
Reference: Salesforce Many-to-Many Relationships
Why Not Other Options?
A) Master-detail field from Applicant to Job â Would enforce a one-to-many relationship (one Applicant to many Jobs), but not the reverse.
B) Formula field on Applicant that references Job â Formula fields cannot establish relationships, they only display data.
D) Lookup field from Applicant to Job â Would only allow one Job per Applicant, not multiple.
Key Consideration:
If the requirement were one Applicant to many Jobs (but not vice versa), a lookup (Option D) would work.
But since both sides need "many" relationships, a junction object (Option C) is mandatory.
Universal Hiring uses Salesforce to capture job applications. A salesforce administrator created two custom objects; Job c acting as the maste object, Job _Application c acting as the detail. Within the Job c object, a custom multi-select picklist, preferred Locations c, contains a list of approved states for the position.
Each Job_Application c record relates to a Contact within the system through a master-detail relationship. Recruiters have requested the ability to view whether the Contact's Mailing State value matches a value selected on the Preferred_Locations c field, within the Job_Application c record. Recruiters would like this value to be kept in sync if changes occur to the Contact's Mailing State.
What is the recommended tool a developer should use to meet the business requirement?
A. Roll-up summary field
B. Apex trigger
C. Formula field
D. Record-triggered flow
Explanation:
The business requirement is to display whether a Contactâs Mailing State matches any value in the Preferred_Locations__c multi-select picklist on the Job__c object, within the related Job_Application__c record, and to keep this value in sync when the Contactâs Mailing State changes. Letâs analyze why a record-triggered flow is the recommended tool and why the other options are less suitable.
Why D. Record-triggered flow?
A record-triggered flow is a declarative automation tool in Salesforce that can be triggered when a record is created or updated. Itâs ideal for this scenario because:
1. It can evaluate the Contactâs MailingState (from the Contact object) against the Preferred_Locations__c multi-select picklist on the related Job__c object (via the Job_Application__c master-detail relationship).
2. It can update a field on the Job_Application__c record (e.g., a checkbox or text field) to indicate whether the Contactâs MailingState matches any value in Preferred_Locations__c.
3. It can be configured to run when the Contactâs MailingState is updated, ensuring the Job_Application__c record stays in sync.
4. Flows are declarative, meaning no coding is required, which aligns with Salesforceâs preference for low-code solutions when possible, reducing maintenance overhead.
How it works:
1. Create a record-triggered flow on the Contact object that triggers on create or update when MailingState changes.
2. Use a Get Records element to retrieve related Job_Application__c records and their associated Job__c records.
3. Use a decision element to check if Contact.MailingState is contained in Job__c.Preferred_Locations__c (using the CONTAINS function for multi-select picklists).
4. Update a field on Job_Application__c (e.g., a checkbox Is_Location_Match__c) based on the result.
Why itâs recommended:
Itâs a scalable, maintainable, and declarative solution that avoids custom code, aligning with Salesforce best practices for the Platform Developer I exam.
It can handle complex logic (e.g., multi-select picklist comparisons) without requiring Apex.
Why not the other options?
A. Roll-up summary field:
1. Roll-up summary fields are used to aggregate data (e.g., count, sum, min, max) from detail records to a master record in a master-detail relationship. They cannot perform complex logic like comparing a Contactâs MailingState to a multi-select picklist (Preferred_Locations__c) on the master Job__c object.
2. Roll-up summaries are limited to simple calculations and cannot dynamically check for matches or update fields based on external object data (e.g., Contactâs MailingState).
3. This option is incorrect because it doesnât meet the requirement for dynamic comparison or synchronization.
B. Apex trigger:
An Apex trigger on the Contact object could achieve the requirement by:
1. Triggering on update of MailingState.
2. Querying related Job_Application__c and Job__c records.
3. Comparing MailingState with Preferred_Locations__c using Apex logic (e.g., splitting the multi-4. select picklist values).
4. Updating a field on Job_Application__c.
However, Apex is a coded solution, and Salesforce encourages declarative tools (like flows) over code when the functionality can be achieved declaratively, especially for the Platform Developer I exam, which emphasizes low-code solutions where possible.
While technically feasible, an Apex trigger is overkill and increases maintenance compared to a flow.
C. Formula field:
A formula field on Job_Application__c could theoretically compare Contact.MailingState (accessed via the master-detail relationship) to Job__c.Preferred_Locations__c using the INCLUDES function for multi-select picklists.
Example formula:
INCLUDES(Job__r.Preferred_Locations__c, Contact__r.MailingState)
This would return true if the MailingState matches any value in Preferred_Locations__c.
However, formula fields are recalculated on read (not stored in the database), which can lead to performance issues if used extensively in reports or list views. More importantly, formulas cannot trigger updates or ensure synchronization when MailingState changesâthey are passive and only display data.
The requirement to âkeep in syncâ suggests an active update process, which a formula field cannot provide. Thus, itâs not the best fit.
Key Considerations:
Master-Detail Relationships:
Job__c is the master of Job_Application__c, and Contact is the master of Job_Application__c. This allows the flow to navigate relationships (e.g., Job_Application__c.Job__r.Preferred_Locations__c and Job_Application__c.Contact__r.MailingState).
Multi-Select Picklist:
The Preferred_Locations__c field requires a CONTAINS or INCLUDES check to compare against MailingState. Flows can handle this using formula expressions or decision elements.
Synchronization:
The requirement to keep the value in sync when MailingState changes implies an active update process, which flows can handle by triggering on Contact updates.
Declarative vs. Code:
The Platform Developer I exam prioritizes declarative solutions (e.g., flows) over coded solutions (e.g., Apex) when the requirement can be met without code, as per Salesforce best practices.
Reference:
Salesforce Documentation:
Record-Triggered Flows: Explains how to create flows that trigger on record changes.
Work with Multi-Select Picklists in Flows: Details on handling multi-select picklists in flows.
Salesforce Flow Developer Guide: Covers flow capabilities for automation.
Trailhead:
Automate Your Business Processes with Salesforce Flow: Practical guide to building record-triggered flows.
Salesforce Platform Developer I Certification Study Guide: Emphasizes declarative tools for automation.
Which three steps allow a custom SVG to be included in a Lightning web component? Choose 3 answers
A. Upload the SVG as a static resource.
B. Import the static resource and provide a getter for it in JavaScript.
C. Reference the getter in the HTML template.
D. Reference the import in the HTML template.
E. Import the SVG as a content asset file.
Explanation:
To include a custom SVG in a Lightning Web Component (LWC), you typically follow these steps:
â
A. Upload the SVG as a static resource
SVGs need to be hosted in Salesforce so that they can be referenced. The most common method is to upload the file as a static resource.
Navigate to Setup > Static Resources, then upload your .svg file.
đš Reference: Salesforce Dev Guide â Static Resources
â
B. Import the static resource and provide a getter for it in JavaScript
In your component's .js file:
import mySvg from '@salesforce/resourceUrl/mySvg';
export default class MyComponent extends LightningElement {
get svgUrl() {
return mySvg;
}
}
The SVG file is imported using the @salesforce/resourceUrl directive.
The getter (svgUrl) can then be used in the HTML template to refer to the file.
â
C. Reference the getter in the HTML template
In your componentâs .html file:
< img src="{svgUrl}" alt="My SVG Icon" >
The getter svgUrl is used to bind the source of the image dynamically.
â Why the others are incorrect:
D. Reference the import in the HTML template
You cannot directly reference the import variable in the HTML template â it must go through a class property or getter.
LWC templates only support binding to component instance properties (not module-level variables).
E. Import the SVG as a content asset file
This refers to Content Assets in Salesforce CMS, which is not the standard or recommended way to include SVGs in LWCs.
Content assets require additional setup and are typically used in Experience Cloud sites, not in LWC components by default.
What is the result of the following code snippet?
A. Accounts are inserted.
B. Account Is inserted.
C. 200 Accounts are inserted.
D. 201 Accounts are Inserted.
Explanation:
Loop Analysis:
1. The loop runs from i = 0 to i <= 200, which means it executes 201 times (not 200, because it includes both 0 and 200).
2. Each iteration performs an insert acct operation, inserting the same Account object repeatedly.
Governor Limit Consideration:
1. Salesforce enforces a DML governor limit of 150 statements per transaction (in synchronous contexts).
2. This code attempts 201 DML operations, which would exceed the limit and throw a LimitException.
3. However, the question asks what the code does (not whether it succeeds), so the correct answer is based on the loop logic.
Why Not Other Options?
A) Accounts are inserted â Too vague; the question asks for the exact count.
B) Account is inserted â Implies only one insertion, but the loop runs 201 times.
C) 200 Accounts are inserted â Incorrect; the loop runs 201 times (i <= 200).
Key Takeaway:
The code attempts to insert 201 Accounts but would fail due to governor limits.
If this were a real scenario, youâd need to:
. Move the insert outside the loop (e.g., bulkify with a list).
. Or use i < 200 to limit iterations to 200.
Reference: Salesforce Governor Limits
What should a developer use to fix a Lightning web component bug in a sandbox?
A. Developer Console
B. VS Code
C. Force.com IDE
Explanation:
To fix a Lightning Web Component (LWC) bug in a sandbox, a developer should use Visual Studio Code (VS Code), as itâs the recommended tool for modern Salesforce development. Hereâs why:
Why B. VS Code?
VS Code, with the Salesforce Extension Pack, provides a robust environment for LWC development, including debugging, code editing, and deployment to sandboxes. It supports the Salesforce CLI, enabling developers to retrieve, edit, and deploy LWC metadata efficiently.
It offers features like IntelliSense, linting, and debugging tools tailored for LWC, making it ideal for identifying and fixing bugs in JavaScript, HTML, or Apex called by the component.
Example workflow: Retrieve the LWC from the sandbox using sfdx force:source:retrieve, debug locally, and deploy fixes with sfdx force:source:deploy.
Why not the other options?
A. Developer Console:
The Developer Console is a browser-based tool for Apex and Visualforce development, but it lacks robust support for LWC debugging. Itâs not suited for editing or deploying LWC metadata (JavaScript, HTML, CSS) and is limited for modern web development.
C. Force.com IDE:
The Force.com IDE (based on Eclipse) is outdated for LWC development. It was designed for older Salesforce technologies (e.g., Visualforce, Aura) and lacks support for LWCâs modern web standards and Salesforce CLI integration.
Key Considerations:
VS Code is Salesforceâs recommended IDE for LWC development, offering seamless integration with sandboxes via the Salesforce CLI.
Debugging LWCs requires tools that support JavaScript and modern web standards, which VS Code provides.
Reference:
Salesforce Developer Guide: Develop Lightning Web Components: Recommends VS Code for LWC development.
Trailhead: Quick Start: Lightning Web Components: Guides on setting up VS Code for LWC.
A developer migrated functionality from JavaScript Remoting to a Lightning web component and wants to use the existing getOpportunities() method to provide data. What to do now?
A. The method must be decorated with (cacheable=true).
B. The method must be decorated with @AuraEnabled.
C. The method must return a JSON Object.
D. The method must return a String of a serialized JSON Array.
Explanation:
To make an Apex method callable from a Lightning Web Component (LWC), you must decorate it with the @AuraEnabled annotation and make it public or global static.
So, if you're migrating from JavaScript Remoting (used in Visualforce) to Lightning Web Components, here's what must happen:
â
B. The method must be decorated with @AuraEnabled
This annotation allows the method to be exposed to the Lightning framework.
Specifically, for LWC to call Apex methods, the method must be:
@AuraEnabled
public static
Ideally marked as cacheable=true if it's read-only and suitable for caching.
Example:
public with sharing class OpportunityController {
@AuraEnabled
public static List
return [SELECT Id, Name, StageName FROM Opportunity LIMIT 10];
}
}
đš Reference: Salesforce LWC Apex Methods Documentation
â Why the others are incorrect:
A. The method must be decorated with (cacheable=true)
This is optional, not required.
You use cacheable=true only if the method:
. Does not modify data
. Is suitable for client-side caching
But it's not mandatory to use cacheable=true to call the method from LWC.
C. The method must return a JSON Object
Incorrect. Apex methods can return native Salesforce types like List
The framework automatically serializes the return value into JSON â you donât have to.
D. The method must return a String of a serialized JSON Array
Incorrect and unnecessary.
Manually serializing data is not needed. The Lightning runtime handles serialization and deserialization between Apex and LWC automatically.
What are two considerations for running a flow in debug mode? Choose 2 answers
A. Callouts to external systems are not executed when debugging a flow.
B. Clicking Pause or executing a Pause element closes the flow and ends debugging.
C. Input variables of type record cannot be passed into the flow,
D. DML operations will be rolled back when the debugging ends.
Explanation:
- Callouts to external systems are not executed when debugging a flow because the debug mode runs in a controlled environment where external interactions are prevented.
- DML operations (such as inserts, updates, and deletes) are rolled back when debugging ends, ensuring that test runs do not affect actual data.
A developer Is asked to create a Visualforce page that lists the contacts owned by the current user. This component will be embedded In a Lightning page. Without writing unnecessary code, which controller should be used for this purpose?
A. Standard list controller
B. Standard controller
C. Lightning controller
D. Custom controller
Explanation:
Standard list controllers are used when you need to display a list of records (like Contacts). Since the requirement is to list contacts owned by the current user, and there's no mention of custom logic, a standard list controller for the Contact object is the most efficient and appropriate choice.
It provides built-in pagination, filtering, and sorting without the need for custom Apex code.
This is ideal for use cases where basic list display is enough, especially when embedding into a Lightning page.
Other options:
B. Standard controller: Used for a single record, not a list.
C. Lightning controller: This is not a standard Visualforce optionâconfusing terminology.
D. Custom controller: Unnecessary unless you need custom logic, which this question does not require.
Page 1 out of 20 Pages |