Lightning Web Components Flashcards

1
Q

What happens if you try to directly modify an object passed from a parent to a child?

A

An invalid mutation error is thrown.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

True or false: bound properties in {} can contain spaces.

A

False.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the easiest way to work with Salesforce data in an LWC?

A

Use base Lightning components built on the Lightning Data Service (LDS).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Which property of an event includes any sent data?

A

detail

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the syntax for loading the account object into a variable named ACCOUNT_OBJECT?

A

import ACCOUNT_OBJECT from “@salesforce/schema/Account”;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Which two properties does a record page provide?

A

recordId and objectApiName

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How do you conditionally display content in an LWC?

A

Nest a template tag(s) with the lwcI:if={someProperty}. The lwc:elseif and lwc:else properties can also be used.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How would you reference a component named viewSource in markup?

A

<c-view-source>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How do you conditionally render markup in LWCs?

A

Use the lwc:if, lwc:elseif, and lwc:else attributes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the preferred, and easiest way to work with data in an LWC?

A

Lightning Data Service.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

In which directory are message channels stored?

A

force-app/main/default/messageChannels

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the proper syntax to import a method named myMethod from MyClass as MY_METHOD?

A

import MY_METHOD from ‘@salesforce/apex/MyClass.myMethod;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is a slot?

A

A placeholder for markup that a parent component passes into a component’s body.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the file name format for a message channel?

A

messageChannelName.messageChannel-meta.xml

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Which method is used for dispatching events?

A

dispatchEvent()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Which decorator exposes a field as a public property?

A

@api

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Which attribute is set to listen for an event on an input element?

A

onchange

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

True or false: if you write a setter for a public property, you must also write a getter.

A

True.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What would be the property syntax to import the method named queryAccounts that is marked @AuraEnabled and part of the class AccountListController into an LWC?

A

import queryAccounts from ‘@salesforce/apex/AccountListController.queryAccounts’;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

Which decorator marks a field as public?

A

@api

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

True or false: an LWC folder and its file must have the same name, including capitalization and underscores.

A

True.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

True or false: all fields are reactive.

A

True.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

True or false: an LWC file/folder must begin with a lowercase letter.

A

True.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

How do you control when Apex method invocation occurs in an LWC?

A

Call the method imperatively.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

An array of Contact fields has been declared named FIELDS. What is the proper syntax to use these fields when wiring in to a property?

A

@wire(getRecord, {recordId: ‘$recordId’, fields: FIELDS})

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

What is the syntax to create a child component named myComponent and set a public property named myProperty to the value of a primitive named test?

A

<c-my-component my-property="test"><c-my-component>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

What decorator must be used to call an Apex method from an LWC?

A

@AuraEnabled

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q

What would the syntax be to define an iterator named it that iterates over an array named accounts?

A

<template iterator:it={accounts}>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
29
Q

What is required to expose an Apex method to an LWC?

A

The method must be static, either global or public, and annotated with the method @AuraEnabled.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
30
Q

What is the filename for a component configuration file for an LWC named myComponent?

A

myComponent.js-meta.xml

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
31
Q

True or false: an Apex method that isn’t annotated with cacheable=true must be called imperatively.

A

True.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
32
Q

How do you make an LWC visible in an org?

A

In the metadata component file, set the <isExposed> attribute to true and create <target> attribute(s) nested inside a <targets> attribute to specify which types of pages the component be added to.</targets></target></isExposed>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
33
Q

Which properties does a wired property have by default?

A

data and error

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
34
Q

What is the default namespace for custom Lightning Web Components?

A

c

35
Q

Which base components handle working with Salesforce data?

A

lightning-record-form, lightning-record-edit-form, and lightning-record-view-form

36
Q

From which module are Apex classes imported?

A

@salesforce/apex

37
Q

Which event value determines whether or not the event can pass the shadow boundary?

A

composed

38
Q

What are the parameters to the message channel’s publish function?

A

A message context, a message channel, and the message payload.

39
Q

How do you send data when dispatching an event?

A

Include as the second argument to the CustomEvent constructor an object with a detail property equal to the data that you wish to send.

40
Q

How do camel case component folder names map to markup?

A

Using kebab-case

41
Q

What is the prefix for reactive variables?

A

$

42
Q

Which suffix do message channels use when imported?

A

__c (though they are not custom objects)

43
Q

From which module are message channels imported?

A

@salesforce/messageChannel

44
Q

What is the syntax to conditionally render HTML in an LWC based upon the value of myBoolean being true?

A

<template lwc:if={myBoolean}></template>

45
Q

What is the default namespace for base LWCs?

A

lightning

46
Q

How do you use a lightning-record-form to create a record?

A

Leave out the record-id attribute.

47
Q

From which module is track imported?

A

lwc

48
Q

True or false: defining a setter method is required in LWCs.

A

False. Setter methods are optional.

49
Q

True or false: all wire adapters respect object CRUD rules, field-level security, and sharing.

A

True.

50
Q

Which lifecycle hook is called when every time a component renders (and rerenders)?

A

renderedCallback()

51
Q

Which event value determines whether or not the event moves up through the DOM?

A

bubbles

52
Q

From which module are static resources imported?

A

@salesforce/resourceUrl

53
Q

What does it mean that fields are reactive in LWCs?

A

If a field is used in a template, or indirectly in a getter of a property that’s used in a template, the component rerenders when the property’s value changes.

54
Q

What is the syntax to dispatch a custom event named “selected” and send this.contact.Id as data along with the event?

A

this.dispatchEvent(new CustomEvent(“selected”, {detail: this.contact.Id}));

55
Q

How does the framework identify each item so that it can rerender only the item that changed?

A

Every item in a list is assigned a unique key, which must be a string or a number.

56
Q

From where is the getRecord wire adapter imported?

A

‘lightning/uiRecordApi

57
Q

What is the root tag in an LWC HTML file?

A

<template>
</template>

58
Q

True or false: the value property of an input element is updated automatically on every change.

A

False.

59
Q

How many SVG icons can you have per LWC?

A

One.

60
Q

Which template directive allows you to access special behavior for a list such as the index of the item and whether or not the item is the first/last item in the list?

A

iterator

61
Q

Which module is wire imported from?

A

lwc

62
Q

Why would a template have nested <template> tags?</template>

A

To use directives, such as lwc:if, lwc:else, and for:each.

63
Q

A parent component will contain a child component named myComponent. myComponent fires previous and next components, which are handled by the parent component methods previousHandler and nextHandler, respectively. What is the syntax to insert the child component?

A

<c-my-component onprevious={previousHandler} onnext={nextHandler}></c-my-component>

64
Q

What is the syntax to call a method called myMethod in a child component named myComponent from a parent component?

A

this.template.querySelector(“c-my-component”).myMethod();

65
Q

How do you call a method in a child component from a parent component?

A

Expose the method by decorating it with @api. Then, use thiss.template.querySelector to find the child component and call the method.

66
Q

From which module are objects and fields loaded?

A

@salesforce/schema

67
Q

What is the syntax to create a child component named myComponent and set a public property named myProperty to the value of an object named test?

A

<c-my-component><c-my-component></c-my-component>
</c-my-component>

68
Q

What is the syntax to iterate over a property named contacts and to access the current item as contact?

A

<template for:each={contacts} for:item=”contact”>

69
Q

Which lifecycle hook is called when a component is inserted into the DOM?

A

connectedCallback()

70
Q

How does the custom LWC myComponent render in HTML?

A

<c-my-component>
</c-my-component>

71
Q

Given an iterator named it that iterates over a property named accounts, how would you get the name property of the current account?

A

it.value.name

72
Q

What is the preferred way to navigate programmatically from a LWC?

A

The Lightning Navigation Service.

73
Q

What are the parameters given to the @wire annotation to call an Apex method?

A

The name of the Apex method and an object containing the parameters for the method.

74
Q

Which wire adapter is used to get a record’s data?

A

getRecord

75
Q

What is the base class for Lightning Web Components?

A

LightningElement

76
Q

What are the parameters to the message channel’s subscribe method?

A

The message context, the name of the message channel, and a listener method that handles the published message.

77
Q

How many decorators can a single property or function have?

A

One.

78
Q

From which package is NavigationMixin imported?

A

lightning/navigation

79
Q

Which module is imported to work with navigation in LWCs?

A

NavigationMixin

80
Q

Which method is called to handle navigation in an LWC?

A

NavigationMixin.Navigate

81
Q

What is the syntax to load the Account object’s name field as NAME_FIELD?

A

import NAME_FIELD from “@salesforce/schema/Account.Name”;

82
Q

How do you get a recordId in an LWC?

A

Declare a recordId property and decorate it with @api. The flexipage will populate the recordId property.

83
Q

What is the syntax to dispatch an event named “next”?

A

this.dispatchEvent(new CustomEvent(“next));