30 Salesforce Lightning Developer Interview Questions
30 Salesforce Lightning Developer Interview Questions
6. What are the types of attributes that we can use to store values?
We can use different types of attributes, listed below:
String
Integer
Boolean
Date
Datetime
Double
Decimal
Long
Array
List
Set
Map
Standard object attribute – example: <aura:attribute name=”contactObj”
type=”Contact”
Custom object attribute – example A: aura:attribute name=”customObjectList”
type=”customObject__c[]”/>OR example B: <aura:attribute
name=”customObject” type=”customObject__c”/>
8. How can you call a javascript controller action from a component markup?
We can use action provider to call a javascript controller action from the
component markup, for example:
In the controller:
({
doSubmit:function(component, event, helper) {
// Some operations.
)}
9. Which interface should you use if you want to get the id of the record from the
record Detail page?
You can use the force:hasRecordId interface. Use this as opposed to the
{!v.recordId} in controller we can get the id of the current record.
10. Which interface should you use if you want your component to be available for
all pages?
You can use the flexipage:availableForAllPageTypes interface.
11. Which interface should you use if you want to override a standard action?
You will need to use the Lightning:actionOverride interface.
12. Which interface should you use if you want your component to be available
only on the record home page?
You will need to use the flexipage:availableForRecordHome interface.
13. Which interface should you use if you want your component to be used a tab?
You will need to use the force:appHostable interface.
14. Which interface should you use if you want your component to be used a quick
action?
You will need to use the force:lightningQuickAction interface.
15. How can you detect a change in an attribute value, and call a controller method
based on a change?
You can use of the below handler:
<aura:handler
name="change"value="{!v.<strong>attributeNameWhereValueChangeOcc
ured</strong>}"action="{!c.doinit}"/&>
Note: attributeNameWhereValueChangeOccured is the attribute name where
we are detecting the change.
16. How can you call the controller method based on a component load?
We can make use of the below handler:
INSIDE ParentComponentController.js
var childCompId=component.find("ChildCompId");
var res=childComponent.chilCompMethod("From parent");
INSIDE ChildComponent.cmp
<aura:component>
<aura:method name="chilCompMethod" action="{!c.doAction}">
<aura:attribute name="receiveValueFromParent" type="String"/>
</aura:method>
</aura:component>
INSIDE ChildComponentController.js
({
doAction:function(component, event, helper){
var params=event.getParam('arguments');
if(params)
{
var param1=params.receiveValueFromParent;}
return param1+"Appended child value";}
)}
20. How can you define field level security in Lightning Components?
You will need to use Lightning:recordForm, Lightning:recordEditForm,
Lightning:recordViewForm, force:recordData.
21. What is Lightning Out?
If you want to use your component on an external site, you will need to use
Lightning Out. The best advantage of Lightning Out is you can use the Lightning
Component inside a Visualforce page and vice versa.
For more information on Lightning Out and how you can use Visualforce inside a
Lightning component (and vice versa), check out our Salesforce Summary article
on this topic.
22. What is force:recordData, and what are its advantages?
force:recordData is a standard controller of a Lightning Component. We can
perform an operation such as creating a record, editing a record,deleting a record
using force:recordData. If we are using force:recordData, it identifies and
eliminates the duplicate request going to the server if they are requesting for the
same record data (which in turn improves performance).
23. What are all component bundles we deal with while working with Lightning
Component?
Following are the component bundles we deal with while working with Lightning
Component.
Component: contains markup.
Controller: handles the client side events.
Helper: write the common logic inside helper which can be used by different
controller methods, avoiding repetition.
Style: contains the style for the component.
Documentation: used to record the component’s use.
Renderer: contains the default rendering behaviour of a component.
SVG: the icon which gets displayed before the component name in the
Lightning App Builder.
Design: control which attribute we can expose to tools like the Lightning App
Builder. It helps with component re-usability.
26. How do the bubble phase and the capture phase propagate?
Bubble phase: propagates from Bottom to Top.
Capture phase: propagates from Top to Bottom.
<c:ChildComp childAttributeName="{!v.parentAttributeName}">
</aura:component>
childAttributeName=“{!v.parentAttributeName}” is a bound expression, change
to the value of the childAttributeName attribute in child component also changes
the value of parentAttributeName attribute in parent component and vice versa.
An example of an unbound expression:
<aura:component>>
<c:ChildComp childAttributeName="{#v.parentAttributeName}">;
</aura:component>
{
"type": "standard__component",
"attributes": {
"componentName": "c__MyLightningComponent
},
"state": {
"myAttr": "attrValue"
}
}
https://www.sfdc-lightning.com/p/salesforce-interview-questions.html
1)App Page
2)Home Page
3)Record Page
Value provider is a way to access data,with value provider "v" we can fetch value
of attribute from component markup in javascript controller.Value provider is
denoted with v(view) and action provider is denoted with "c "(controller).
Value provider:
<aura:component>
{!v.myfirstattribute}
</aura:component>
Action provider:
In Javascript controller,
({
})
1)Array
2)List
3)Map
4)Set
7) What is the use of interface force:hasRecordId and
flexipage:availableForAllPageTypes in Salesforce Lightning component?
Basic Syntax:
13) What is the use of aura:handler change event in the Salesforce Lightning
component?
The change event is called when the value in one of the attribute changes.
As an Example If i am having attribute " Anyname", on change of attribute
"Anyname" if I want to call javascript method i can do this as:
Syntax:
16) What is the main advantage of using Component event over application
events?
We should always use Component Events whenever possible this is because
Component events can only be handled by parent components so the components
in picture are only those components which need to know about them.
we can directly call a child component controller method from the parent
component controller method using Aura:method. This method is used to pass
value from parent component controller to the child component controller.
Lightning Component
Knowledge Article
Named Page
Navigation Item Page
Object Page
Record Page
Record Relationship Page
Web Page
Lightning Data Service (LDS) act as the data layer for Lightning.
If we are not using LDS, every component within our app makes independent calls
to the server to perform operations on a record, even if all components within our
app are dealing with same record data. These are independent server calls which
reduces performance.LDS identifies and eliminates requests that involve the same
record data, sending a single shared data request that updates all relevant
components, it also provides a way to cache data to work offline in case the user
gets disconnected, intelligently syncing the data once the connection is restored.If
we have a Lightning application that creates, reads, updates, or deletes records,
LDS is the best, most efficient way to do CRUD operations.
25) What are the method available with force:recordData and What are the
supported mode?
mode can be either EDIT or VIEW.(View for displaying records, edit for creating
or updating records)
27) Which mode we need to use to create record using force:recordData??
mode="EDIT"
<force:recordData aura:id="someId"
recordId="{!v.recordId}"
layoutType="{!v.layout}"
fields="{!v.fieldsToQuery}"
mode="VIEW"
targetRecord="{!v.record}"
targetFields="{!v.simpleRecord}"
targetError="{!v.error}"
/>
recordUpdated.
Sample syntax:
<force:recordData aura:id="forceRecordDataCmp"
recordId="{!v.recordId}"
layoutType="{!v.layout}"
targetRecord="{!v.recordObject}"
targetFields="{!v.recordFieldstoQuery}"
targetError="{!v.recordError}"
recordUpdated="{!c.recordUpdated}" />
For every force:recordData component referencing the updated record, LDS does
two things.
LDS notifies all other instances of force:recordData of the change by firing
the recordUpdated event with the
appropriate changeType and changedFields value.
It sets the targetRecord and targetFields attribute on each force:recordData
to the new record value. If targetRecord or targetFields is referenced by any UI,
this automatically triggers a rerender so that the UI displays the latest data.
Lightning out is a feature by which we can use our lightning component inside of
an external site. One of the best advantage is we can use our lightning component
inside visualforce page.
Sample syntax:
recordEvent.setParams({
"entityApiName": "Account",
"defaultFieldValues":{
"Industry":"Apparel"
}
});
Syntax:
});
editRecordEvent.fire();
Lightning:card.
35) On load of lightning component you are required to execute some action
what you will do to achieve this?
We will use "Init" Event which is also called as the constructor of lightning
component.The init event is called once the component construction is over.
Basic Syntax:
36) you are asked to execute some action when value change is detected in one
of the attribute what will you do?
The change event is called when the value in one of the attribute changes.
As an Example If i am having attribute " Anyname", on change of attribute
"Anyname" if i want to call javascript method i can do this as:
Syntax:
37) You are having a requirement to pass value from child component to
parent component which type of event you will use?
We will use Component event. Component event are used in case when there is a
relationship between component. Component Events are fired by the child
components and handled by the parent component.
38) You are having a requirement to pass value from one component to other
component which are not related but a part of same application which type of
event you will use?
We will make use of Application event. Application event are the event handle by
any component no matter what relationship between them but they should be
inside single application.
39) How to ensure field level security while working with lightning
components?
42) What are the requirement to call a server side controller method from
Javascript controller?
Method should be static and must be Aura enabled using @AuraEnabled.
A component bundle contains a component or an app and all its related resources.
When you build lightning component you deal with the following component
bundles,
Component
Mycomp.cmp(Sample component)
or
MycompApp.app(Sample app)
Controller
Controller is used to handle client side events in components.
Ex:
Mycontroller.js
Helper
Contains Javascript functions to handle logic.
Ex: Myhelper.js
Style
Contains styles for the component.
Ex: Mycomp.css
Documentation
Documentation includes description and example to demonstrate the use of
component.
Ex: MyComp.auradoc
Renderer
Contains default rendering behavior for component, We can override this by
custom renderer.
Ex: MyCompRenderer.js
SVG
It is a custom icon resource for components that get displayed before the
component name in lightning app builder or community builder.
Ex: MyComp.svg
Design
File required for components used in Lightning App Builder, Lightning pages,
Community Builder, or Flow Builder.
App
App is used to run the component.
forceCommunity:availableForAllPageTypes
Method:
({
});
action.setCallback(this, function(response) {
var state = response.getState();
if (state === "SUCCESS") {
alert('Contact inserted successfully');
} else if (state === "INCOMPLETE") {
}
});
$A.enqueueAction(action);
}
)}
Explanation:
Component:
<aura:component >
</aura:event>
51) How to get the above event i.e(Component event) in Javascript controller
of the component and how to fire it?
cmpEvnt.setParams({
storeMessage : component.get("v.textMessage") // Setting some
parameter on event
});
cmpEvnt.fire(); // Firing the event
52) How to handle the above event i.e(Component event) in the parent
component?
<aura:component >
<!--Handling the event fired from child component, Specify the name with
which the event was registered in child component and the event along with
the action to be performed-->
<aura:handler name="registrationInChild" event="c:CompEvent"
action={!c.doHandleFromChild}"/>
<aura:attribute name="parentMessage" type="String" />
<c:ChildComp/>
</aura:component>
Javascript controller:
({
doHandleFromChild : function(component, event, helper) {
var valueFromEvent=event.getParam("storeMessage");
component.set("v.parentMessage",valueFromEvent);
}
})
Component:
<aura:component >
<!--Name is used to give some name say "registrationInChild" to event during
registration and in the type we specify the event-->
<aura:registerEvent name="regInChild" type="c:AppEvent"/>
<aura:attribute name="textMessage" type="String" default="Part from child
comp"/>
<lightning:button label="Click To Fire" onclick="{!c.doHandleEvent}"/>
</aura:component>
Application event:
</aura:event>
No, It is not necessary to register the application event. It is optional. You can
directly fire the event without registering.
54) How to get the above event i.e(Application event) in Javascript controller
of the component and how to fire it?
var aeEvent=$A.get("e.c:AppEvent");
aeEvent.setParams({
storeMessage : component.get("v.textMessage")
});
aeEvent.fire();
55) How to handle the above event i.e(Application event) in some other
component?
Component:
<aura:component >
<aura:handler event="c:AppEvent" action="{!c.doHandleFromChild}"/>
<aura:attribute name="MessageFromApplication" type="String" />
{!v.MessageFromApplication}
</aura:component>
Controller:
({
doHandleFromChild : function(component, event, helper) {
var valueFromEvent=event.getParam("storeMessage");
component.set("v.MessageFromApplication",valueFromEvent);
}
})
Default phase for the component event is Bubble phase.If we do not specify any
phase it is considered as bubble phase in case of component events.
BottomComp.cmp
<aura:component >
<aura:registerEvent name="propagationEvent"
type="c:CompEventforpropagation"/>
<lightning:button label="Start Event propagation"
onclick="{!c.executeEvent}"/>
</aura:component>
BottomCompcontroller.js
({
executeEvent : function(component, event, helper) {
var cmpEvt=component.getEvent("propagationEvent");
cmpEvt.fire();
}
})
MiddleComp.cmp
<aura:component >
<c:BottomComp/>
<aura:handler name="propagationEvent" event="c:CompEventforpropagation"
action="{!c.doHandleinMiddle}"/>
</aura:component>
MiddleCompcontroller.js
({
doHandleinMiddle : function(component, event, helper) {
alert('From Middle component controller');
}
})
TopComp.cmp
<aura:component >
<c:MiddleComp/>
<aura:handler name="propagationEvent" event="c:CompEventforpropagation"
action="{!c.doHandleinTop}"/>
</aura:component>
TopCompcontroller.js
({
doHandleinTop : function(component, event, helper) {
alert('From top component controller');
}
})
EVENT:
</aura:event>
Application:
OUTPUT:
TopComp.cmp:
<aura:component >
<c:MiddleComp/>
<aura:handler name="propagationEvent" event="c:CompEventforpropagation"
action="{!c.doHandleinTop}" phase="capture"/>
</aura:component>
OUTPUT:
OUTPUT:
OUTPUT:
OUTPUT:
OUTPUT:
OUTPUT:
NOTE:
1)Bubble phase
2)Capture phase
3)Default phase
1) How Can We Use Lightning Components With The Salesforce1 Mobile App
?
By Create a custom Lightning tab that points to our component and include that tab
in our Salesforce1 Mobile navigation.
Lightning Components are use JavaScript on the client side and Apex on the server
side.
Yes, we can inherit styles from parent. there is no need to always defined in the
component.
we can Use < aura:method > to define a method as part of a component’s API. This
enables us to directly call a method in a component’s client-side controller instead
of firing and handling a component event. Using simplifies the code needed for a
parent component to call a method on a child component that it contains.
7) Can We Include One Component To Another ?
there is no limit.
No.
10) What Is Aura? Why Do We Use The Aura: Namespace In The Code?
Aura is the open source technology that powers Lightning Components. The aura:
namespace contains all of the basic building blocks for defining components and
applications.
Lightning App Builder — A new UI tool that lets you build apps lightning
fast, using components provided by Salesforce and platform developers.
Visualforce components are page-centric and most of the work is done on the
server. Lightning is designed from the component up, rather than having the
concept of a page as its fundamental unit. Lightning Components are client-side
centric, which makes them more dynamic and mobile friendly.
Components have been built to be mobile first, but with responsive design in mind.
With Lightning we can build responsive apps fast for desktop, mobile and tablets.
Performance –: Uses a stateful client and stateless server architecture that relies on
JavaScript on the client side to manage UI, It intelligently utilizes your server,
browser, devices, and network so you can focus on the logic and interactions of
your apps.
Event-driven architecture -: event-driven architecture for better decoupling between
components
Yes. we can include the working 3rd party code inside a Visualforce Page; embed
the Visualforce Page inside a Lightning Component. This Lightning Component
can be used as any other Lightning Component in various environments.
Yes! We can use multiple libraries in our lightning component like JQuery,
Bootstrap, custom CSS and custom JavaScript libraries from a local resource (static
resource).
Lightning Experience is the name for the all new Salesforce training desktop app,
with over 25 new features, built with a modern user interface and optimized for
speed.
Q #1) What is Lightning in Salesforce?
Answer: Lightning is a collection of tools and technology for any form of
Salesforce platform. Lightning is inclusive of the following as shown in the
below table:
Sl.
Name Description
No.
1. Lightning It comprises of Lightning Experience, template-based communiti
Experience well as Salesforce 1 mobile app. It is a set of user interfaces with
optimization for speed.
3. Lightning App It offers a fast, easy way of app building and customizations with
Builder and help of drag-and-drop features. Customization of Lightning Expe
Community is done by using Lightning App Builder for a Salesforce 1 mobile
Builder On the other hand community builder helps in customizations of
template-based communities.
4. Lightning Design LDS makes it possible to build apps matching the looks of the
System (LDS) Salesforce 1 mobile app and Lightning experience. It has modern
best practices and style guides.
Sl.
Name Description
No.
3 Helper The developer can write the common logic inside helper used b
different controller methods, avoiding any sort of repetition
7 SVG This icon in the Lightning App Builder gets displayed before th
component.
Sl. Name of Component
Description
No. Bundle
8 Design It not only helps in component reusability but also controls whi
attributes need to exposed for the tools like Lightning App Buil
Q #5) How does Salesforce 1 Mobile app use Lightning components?
Answer: We first create a Lightning tab for the Lightning component and
subsequently include the tab in the navigation select list of Salesforce 1 mobile app
and then the newly created tab to it.
Q #6) Can a Lightning component be used that works with both interfaces –
Mobile and Desktop?
Answer: It is possible to use Lightning components, Salesforce 1 mobile app,
custom standalone apps directly in Lightning Experience as well as template-based
communities. Lightning components are used in the Visualforce page, for use in
Salesforce Visualforce communities as well as the classic environment.
Q #7) Does Lightning Component work with Visualforce?
Answer: Yes, it does work with Visualforce.
Q #8) Can Lightning be viewed as an MVC framework?
Answer: Not really. Lightning is a framework based on components.
Q #9) Which Lightning components parts are server-side and which ones are
client-side?
Answer: For the Lightning component, the client-side is the component page
acting as a JavaScript controller, on the contrary, the server-side acts as an Apex
Controller.
Q #10) What are the differences between Lightning and Visualforce
components?
Answer: Visualforce components are page-centric and work is mostly server-
based. Lightning components, on the other hand, are client-side centric which
accounts for their dynamic, mobile-friendly nature.
Q #11) How to add Aura components to your Visualforce page?
Answer: The developer can add the Aura components to the Visualforce page
in the following three ways:
Use the <apex:includeLightning/> component and add the Lightning
component for the Visualforce JavaScript library used in your Visualforce
page.
Create a reference to a Lightning app for declaring component dependencies.
Use the $Lightning.createComponent() to create the component for a page
by writing a JavaScript function
Q #12) Can we create one component for inheriting style/CSS from the parent
or we need to always define it in the Salesforce component?
Answer: Of course, we can do this. The styles can be inherited from parents and
not necessarily defined in the component.
Q #13) What is the purpose of using Aura: method Tag in Lightning?
Answer: The Aura: method tag can be used for defining a method for component
API. So, there is no need to fire and handle a component event, and it allows us to
directly invoke the method in the component’s controller on the client-side. It also
helps to simplify the code required for a parent component to call a method on a
child component that forms a part of the parent component.
Q #14) Is it possible to include a Lightning component into another?
Answer: Yes, it is possible.
Q #15) What are the limits to the number of components used in an
application?
Answer: There are no limits on the usage number of the components used in an
application.
Q #16) What are Aura Components? Why we use Aura: Namespace in the
code?
Answer: Aura components are the self-contained and reusable units of an app.
Components form the function units of Aura. Aura is the open-source technology
that works for Lightning components. The building blocks for the Aura:
namespace helps to define the components and applications.
Q #17) Are there any CSS (styles) provided by Salesforce.com for Supported
Lightning Components?
Answer: Yes, this is available in Salesforce Lightning Design System.
Q #18) Are Lightning components meant only for mobile apps?
Answer: With a responsive design in mind, Lightning components are meant to be
mobile-first. The components help to build responsive apps faster for desktops,
tablets, and mobile.
Q #19) Is it possible to include external JavaScript/CSS libraries in
components?
Answer: Yes, multiple libraries can be used such as JavaScript/CSS libraries,
jQuery, Bootstrap, etc from a local, static resource.
Q #20) Is it possible to integrate lightning components with a framework such
as Angular?
Answer: It is possible to insert the third-party code within a Visualforce page. The
same Visualforce page is then put inside a Lightning component. Then the same
Lightning Component is used in another Lightning component that works for
various environments.
Q #21) Do you create an App Bundle first to create a Lightning component?
Answer: Not really, however, the component bundle can be created first.
Q #22) Is it possible to deploy components in the production org?
Answer: Yes, deployment of components is possible in the production with
any of the following:
Managed packages
Force.com IDE
Force.com
Change sets
Migration Tool
Q #23) How to create custom Lightning record pages in Salesforce with
Lightning Experience? Can you do the same for Salesforce mobile app?
Answer: Add, remove, or you can even reorder components on a record page for a
custom view of object’s records with the help of Lightning App Builder.
Yes, it is also possible to customize a record page and assign it to the Lightning
apps. The users can access a custom record page for the context of the app they are
working on.
Q #24) Are there any options for Lightning Record Page Assignment?
Answer: It can be assigned in different ways, such as:
Org default
App Default (overrides the assignment at the org level)
App Record Type Profile (overrides the assignment at the org and app level).
Q #25) How to create a custom Lightning Record Page?
Answer: We can create it with the following steps:
Setup->App Builder in Quick Find Box->Select Lightning App Builder-> New-
>Record Page-> Name the page as <xxx>Select Opportunity->Choose Header,
Sub header, Right Sidebar template and Click Finish.
Please go through the link for further details on creating a custom Lightning Page.
Q #26) What are the types of Lightning Record Pages in Salesforce?
Answer: Here are the types enlisted below:
App Page
Home Page
Record Page
Q #27) What are the attributes? What are the parameters required?
Answer: Attributes are the variables for storing values. The attribute is defined
with a name, type, default, description, and access. The <aura:attribute> tag is
used that requires the values of name and type attributes.
However, name and type are the only required parameters. This is shown below:
Q #28) Which interface to use if you want your component to be available for
all pages?
Answer: You can use the flexipage:availableForAllPageTypes interface.
Q #29) Which interface can be used to get the id of the record from the
record Detail page?
Answer: The force:hasRecordId interface can be used for getting rid of the
record from the record Detail page.
Q #30) Which interface should be used to override a standard action?
Answer: Here you can make use of the Lightning:actionOverride interface.
Q #31) Which interface is for using components in a quick action?
Answer: The interface used here is force:lightningQuickAction.
Q #32) Which interface to use a component in the record home page?
Answer: The interface used here is flexipage:availableForRecordHome.
Q #33) Which interface is used if you want a component to be used as a tab?
Answer: The interface used here
is force:appHostable.