LWC Development Guide and JavaScript Basics
LWC Development Guide and JavaScript Basics
1. Introduction of LWC
Introduction of LWC
ECMAScript Script 7
Difference between Aura Component & LWC
Advantages of LWC
2. Setup Environment and scratch Org
Create Basic LWC Component
Understand the Web Components Folder Structure
Modules in Lightning Web Components
Data Binding
Decorators for properties (@wire,@track,@api)
Behavior of properties
Create LWC Actions (onClick, onChange..etc)
Data flow in Lightning Web Components
Setter & Getter methods
Iterators in LWC
Invoking methods on child components
All about Slots
Lifecycle Hooks
Hooks in LWC
Shadow Dom Web Standard
4. LWC with SLDS
1
How to dispatch and handle events
How Event Retargeting works?
Event Propagation in JavaScript
Event bubbling in child and parent components
All Event propagation scenarios
Programmatically handle the events
Publish-Subscribe events
6. LWC & APEX
Introduction
Putting the base component lightning-record-edit-form to use
Using lightning-record-view-form and lightning-record-view-form
Using getRecord() Adapter
Handlers in LDS base components
Override save functionality using base components
Using createRecord() method to create a record
Using updateRecord() method to update a record
getRecord() alternative syntax
8. Navigation in LWC
2
3
4
5
-------------------------------------------------------------------------------------------------
Src =[Link]
JavaScript
JavaScript
6
JavaScript is a scripting or programming language that allows you to implement
complex features on web pages
It brings interactivity to the web pages
Variables
Data types in JS
7
1. Array
2. Date
3. Math
4. String
5. etc.
Equability Comparison
=== This operator does value plus data type comparison Example 100===‖100‖
Spread Operator
Destructuring
The two most used data structures in JavaScript are Object and Array
8
Destructuring is special syntax that allows us to ―unpack‖ arrays or objects into a bunch of
variables, as sometimes that‘s more convenient.
Array destructuring
Object destructuring
let options ={
title:"Zeroto to Hero",
description:"Learn JavaScript",
Age : 30,
type:"CRM"
}
let {title, description, Age, type} = options;
[Link](title); // Zeroto to Hero
String Interpolation-(`${}`)
String interpolation allow you to embed expression in string
Template string use the back-ticks(``) rather then the single or double quotes.
(`${firstName} ${lastName}`);
recordId= 2774444;
String methods
JavaScript provides many methods to play with strings. Below are some of the most
commonly used srings method in LWC
[Link]() [Link]()
9
Object/JSON Operation
Array Methods
1. map() - loop over the array and return new array based on the value return.
a. let newArry = [Link](function(element, index, array) {
b. [Link](`Element: ${element},Index: ${index}, Array: ${array}`);
c. return element * 2; // Example operation: double each element
d. });
2. every() - return true or false if every element in the array satisfy the condition
a. return element >=18; o/p true
3. filter() - return new array with all the elements that satisfy the condition
a. let filteredArray = [Link](function(element, index, array) {
b. return element > 5; // Example condition: keep elements greater than 5
c. });
4. some() - return true if at least one element in the array satisfy
5. sort() - sort the elements of an array
a. let sortedArray = [Link](function(a, b) {
b. return a - b; // Example: sort in ascending order
c. });
d. [Link](sortedArray); // Output: [2, 3, 5, 6 , 7, 8, 9, 10]
6. reduce() - this method reduces the array to a single value (left to right)
7. forEach() - this method calls for each array element(it never retun)
Promise
10
Promise is an object that may produce a single value sometime in the future.
Promise is used to handle asynchronous operation in JavaScript.
Export
Exporting – Use export keyword to export many variables or much method from a file
export const name = "John Doe";
Default export – Use export default keyword to export only one variable or method from a
file
export default user = "Salesforce Hero";
Import
Importing – Use import keyword to import variable or method from a given file path or
module.
Multiple imports
11
Import * as tutils from :/filepath
querySelector
The querySelector() method returns the first element that matches a specified CSS
selector(s) in the document.
[Link](selector);
querySelectorAll
The querySelectorAll() method returns all elements in the document that matches a
specified CSS selector(s), as a static NodeList object.
[Link](selector);
Event
An event is an action that occurs in the web browser, which the web browser feedbacks to
you so that you can respond to it.
For example, when users click a button on a webpage, you may want to respond to this
click event by displaying a alert box.
Event handler - It is a block of code that will execute when the event occurs. It is also
known as an event listener.
1. HTML Event Handler attribute - When we add event through HTML, Event always
begin with on keyword like onclick, onchange, onkeyup
2. Event Listener - Event Handlers provide two main methods for dealing with the
registering/deregistering event listeners:
Event Propagation
12
Event Propagation explains the order in which events are received on the page from the
element where the event occurs and propagated through the DOM tree.
1. Event bubbling
2. Event Capturing
Event Bubbling
In the event bubbling model, an event starts at the most specific element and then flows
upward toward the least specific element (the document or even window).
Custom Event
In JavaScript we can create our own custom event using CustomEvent constructor
Syntax
Arrow Function
Arrow function allows us to write shorter function syntax.
13
Example:
14
Legacy SFDX Command:
sfdx force:org:create -s -f config/[Link] -d 30 -a recipes
New SF Command:
sf org create scratch -d -f config/[Link] -y 30 -a recipes
Changes:
o Add the scratch subcommand.
o The "assign default org" flag changes from -s to -d.
o The scratch org duration flag changes from -d to -y.
2. Push Source
New SF Command:
sf project deploy start
Changes:
o A significant change; the new command works for all project formats (source or
metadata).
New SF Command:
sf org delete scratch -p -o recipes
Changes:
Add the scratch subcommand.
The target org flag changes from -u to -o.
New SF Command:
sf org assign permset -n recipes
Changes:
15
The topic changes from user to org.
The order of the subcommands changes.
New SF Command:
sf data import tree -p data/[Link]
Changes:
Imports data using the same plan file with slight changes in syntax.
6. Open Org
Legacy SFDX Command:
sfdx force:org:open -p lightning/n/Hello
New SF Command:
sf org open -p lightning/n/Hello
Changes:
Opens the specified Lightning component in the org.
New SF Command:
sf apex test run -c -r human -w 20
Changes:
Command is updated with equivalent flags for test execution.
[Link]
16
camelCase : Each word in the middle of the respective phrase begins with a capital
[Link]
PascalCase: It is same like Camel Case where first letter always is capitalized.
Data binding in the Lightning web Component is the synchronization between the controller and the
template (HTML).
17
Things to remember
1. In template we can access property value directly if it's primitive or object.
2. Dot notation is used to access the property from an object
3. LWC doesn't allow computed expressions like Names[2] or {2+2}
4. The property in { } must be a valid JavaScript identifier or member expression. Like {name} or
{[Link]}
5. Avoid adding spaces around the property, for example, { data }
kkkkk
18
Data Import Wizard Vs Data Import Wizard
Supports custom objects and a few Supports custom objects, and all
standard objects. standard objects.
Can import up to 50,000 records. Can import up to 5 million records.
Can insert, update and upsert records. Can insert, update, upsert and delete
records.
Does not support data export. Supports data export.
Field mappings cannot be saved Field mappings can be saved.
Can bypass workflow rules and Cannot bypass workflow rules and
processes processes.
Does not require software installation Requires Software installation.
Does not provide a command-line Provides a command-line interface
interface.
Data Export service can be used to export org data in monthly or weekly schedule
(depending on edition). Data export is also called as 'Data Export Wizard'.
The export can be scheduled in a weekly and monthly basis. The time, start date and end
date can be specified
Flow Builder, Process Builder, Workflow, and Approvals are declarative tools that
can be used to automate repetitive business processes.
Workflow
19
Outbound Messages—Send a secure, configurable API message (in XML format) to a
designated listener.
Workflow has been an admin's friend for a long time. worknows can:
Update a field
Send an email
Create a Task
Send an outbound message (communication with another system)
These can be initiated when a record is created, whenever it meets a certain condition, or
whenever it is first set to meet a certain condition. The actions can be performed in any
combination and can even have a time delay, rather than be performed immediately.
Email Template
Dear,
I would like to introduce myself as your Account Manager. Should you have any
questions, please feel free to call me at or email me at info@[Link].
Main: 810-545-1000
Sales: 810-545-1222
Fax: 810-545-1001
20
I am confident GenWatt will serve you well and hope to see our relationship grow over
the years.
Best Regards,
Tejram Jatav
Expressions in Visualforce pages are used to bind data between the page and the controller
using getter, setter, and action methods.
Getter method: Retrieves data from the controller and displays it on the
Visualforce page.
Setter method: Sends or saves data from the Visualforce page to the controller.
Action method: Performs an action such as navigation or execution of logic when a
button or link is clicked.
�These methods allow interaction between the user interface and backend logic.
Controllers act as the bridge between the user interface (Visualforce page) and the data.
They provide access to the data and logic needed by the page.
They control what data is shown, how it behaves, and what happens when a user
takes an action (like saving or editing).
All standard and custom objects in Salesforce that are accessible through the API have
standard controllers.
21
Examples: Account, Contact, Opportunity, and even your custom objects
like Employee__c.
These controllers allow basic operations like viewing, editing, and saving records
without writing code.
�Data access: It allows access to the fields of the record and related data (parent
and child records).
�Standard actions: Such as view, edit, save, delete, and cancel.
�These actions make it easy to work with records without writing custom logic.
You need complex business logic not supported by the standard controller.
You want to display or manipulate data beyond what the standard actions allow.
You need to integrate with external systems, callouts, or create multiple record
types at once.
Similarities:
Differences:
22
Feature Custom Controller Controller Extension
Here is the improved and easy-to-understand version of the Visualforce Interview Questions (Part 2)
from your screenshot:
�Example:
public myControllerExtension([Link]
stdController) {
Account acc = (Account)[Link]();
}
Properties simplify controller code by automatically generating getters and setters, which
makes the code easier to read and maintain.
23
Setters run before action methods.
Action methods (like save, delete) run based on user interaction.
[Link]
SelectOption (for dropdowns)
PageReference
[Link]
Wizards handle multiple pages and steps and must maintain the state across those steps.
When you use a custom Visualforce component and need custom logic to control
rendering or actions, then a component controller is needed.
24
HTML
JavaScript
CSS
Even Flash files or embedded media
These are binding expressions used to access variables, methods, or properties from
controllers.
�Example:
<apex:outputText value="{![Link]}"/>
This binds the Name field of the account object from the controller.
16. What are the ways that Visualforce pages can be incorporated into your
user interfaces?
�These allow seamless integration of Visualforce with the standard Salesforce interface.
17. Is it always necessary to know Apex to create Visualforce pages? When does
it become necessary?
No, Apex is not always required. You can use standard controllers and components to
build simple Visualforce pages.
25
18. What are attributes in Visualforce? What is the syntax for including them?
Attributes are modifiers used in Visualforce components or tags. They allow you to pass
values or settings to components.
�Syntax:
�Example:
19. What are the types of bindings used in Visualforce? What do each refer to?
20. What is the main difference between using dataTable and pageBlockTable
tags?
Tag Purpose
21. Which tag is used with radio buttons and picklists to create selectable
values?
�Use:
26
<apex:selectOption>
This tag defines the available options in a dropdown (picklist) or a group of radio buttons.
22. How many controllers does a page have? Where is the controller for a page
assigned?
�Example:
<apex:page standardController="Account"
extensions="myCustomExt">
23. There are a series of layout components that help recreate the traditional
Salesforce layout easily. What name do they share?
<apex:pageBlock>
<apex:pageBlockSection>
<apex:pageBlockTable>
These mimic standard Salesforce layouts and are ideal for user-friendly pages.
24. Which tag should be used to automatically bring in Salesforce label and
default widget for a field?
�Use:
<apex:pageBlock>
It brings in field labels and default UI elements that match the Salesforce standard layout.
Static Resources are files that you can upload to Salesforce and reference in Visualforce
pages. These can include:
27
Images
CSS files
JavaScript files
ZIP files
�Example:
<apex:includeScript value="{!URLFOR($[Link])}"/>
onmouseover
onclick
onchange, onblur, etc.
These events trigger JavaScript functions or Visualforce logic based on user interactions.
AJAX is used to refresh only a part of the page instead of the full page.
The <script> tag allows developers to write JavaScript code directly in the page.
29. What are the different AJAX action tags and what do they do?
Tag Purpose
28
Tag Purpose
actionRegion Defines which part of the page should be updated in partial refresh.
Use AJAX tags to update only a part of the page instead of reloading the entire page.
�Steps:
31. Which tag is used with both radio buttons and picklists to create selectable
values?
�Example:
<apex:selectOptions value="{!picklistValues}"/>
Attributes in components allow passing data and parameters into the component, making
them:
Flexible
Reusable across multiple pages
Customizable for different use cases
�Example:
Here is the improved version of the content with easier explanation and extra clarity:
29
33. How can you access Visualforce component values into JavaScript?
Ans:
To access values of Visualforce components (like input fields, checkboxes, etc.) in
JavaScript, we use the $Component global variable. This helps us refer to components
in our JavaScript code, especially when we want to get or manipulate their values.
Now, if you want to access the value entered in this input field using JavaScript, you can
do so by referring to its ID using the $Component global variable.
<script>
var a =
[Link]('{!$[Link]}').value;
alert("The value entered is: " + a);
</script>
�Explanation:
Salesforce enforces Governor Limits to ensure shared resources are used efficiently
across users and orgs.
These limits control how much code can run and how much data can be processed in a
single execution.
30
✅Key Governor Limits (per execution):
�These limits help avoid overuse of server resources and crashing the system.
�It's like many customers living in the same building but in separate apartments — safe,
isolated, and efficient.
31
37. What is Apex?
Apex is a programming language used to write custom logic on the Salesforce platform.
Key points:
Salesforce Sites allow you to create public websites and applications hosted directly on
Salesforce. These can be accessed:
Built-in Salesforce components (like objects, fields, flows). Fast and simple to
Native
use.
32
Type Description
Custom Objects
Security (profiles, roles, sharing rules)
Workflow rules & approval processes
Reports and Dashboards
Custom Objects store data specific to your organization, like a database table.
33
43. What is a Database Table (in Salesforce)?
Relationships define how two objects in Salesforce are connected using common fields.
�Example: On an Account, you can roll up the total value of all related Opportunities.
48. What are the different types of Picklists and their differences?
Type Description
34
Type Description
Multi-select Picklist User can select multiple options at the same time.
�Example: For a Job Role, we may use standard picklist; for Skills, multi-select.
Field Dependencies help show only relevant picklist values based on another picklist's
value.
�Example:
If Continent = Asia, then Country picklist will only show India, China, etc.
�Makes forms easier and faster to fill.
�Example:
Controlling: Country
Dependent: City
35
They stop the user from saving incorrect data.
Based on custom logic you define.
Page Layouts control how fields and sections appear on a record page:
�In Master-Detail:
Use when:
�Example:
Feedback (child) cannot exist without a Job Application (parent).
36
56. What is a Related List?
A Related List is a section on a record page showing records linked to the current one.
�Example:
Students ⬌ Courses
Create a junction object called Enrollment
Object-Level Can a user access the object at all? (View, Create, Delete)
Record- Can a user see specific records of that object? (Controlled by sharing rules,
Level roles)
�Together, these control what data a user can see and do in Salesforce.
�Example:
A user might see the Account object but not the Annual Revenue field, and also only see
records owned by their team.
Ans: OWDs define the baseline level of access a user has to records they do not own.
37
�Example:
We can set ―Contacts‖ to Private, so users can only see their own contacts unless extra
access is given using Sharing Rules or Role Hierarchies.
Ans: Role Hierarchies allow managers to automatically access all records owned by
users below them in the hierarchy.
�Example:
A Sales Manager can view all records owned by their Sales Reps.
Ans: Sharing Rules allow us to open access to records for specific groups of users
beyond the role hierarchy.
�Used when:
Teams at the same level (e.g., East vs. West Sales) need access to each other‘s data.
Ans: Manual Sharing allows record owners to manually grant access to individual users
who wouldn‘t otherwise have access.
�Example:
If you're reviewing a case, you can share it with your manager directly.
�Permissions it controls:
38
�Example:
Define what a user can do Define what data a user can see (record
Purpose
(permissions) access)
Mandatory? Yes, every user must have one No, not mandatory
�Example:
39
The criteria for when the rule should run.
The actions to take (email, task, field update).
These rules are used to automate tasks based on changes in a record.
Each rule is based on one object and triggers when its criteria are met.
40
73. What are Email Templates?
Ans: Email Templates are pre-designed email formats that you can reuse for automation.
They save time and ensure consistency in communication like welcome emails or
approval notifications.
76. What are the different types of reports that Salesforce supports?
Ans: Salesforce supports 4 main report types:
41
5. Visualforce Page – Custom content like HTML or a form
Primary object
Related objects
Fields
Filters
42
89. What is SOQL?
SOQL (Salesforce Object Query Language) is used to fetch data from Salesforce using
SELECT queries.
�Example:
sql
CopyEdit
SELECT Name FROM Account WHERE Industry = 'Banking'
43
97. What are Apex Governor Limits?
Salesforce sets limits to ensure efficient processing. These include:
44