0% found this document useful (0 votes)
569 views46 pages

30 Salesforce Lightning Developer Interview Questions

This document provides an overview of 30 Salesforce Lightning developer interview questions and answers related to Lightning components. It covers topics such as where Lightning components can be used, how to build them using two programming models, how to create Lightning record pages, options for record page assignment, using attributes to store values, accessing attribute values, calling controller actions from markup, interfaces for different use cases like getting record IDs and overriding standard actions, handling changes in attribute values, component and application events, using aura:method to pass values between parent and child components, defining field level security, what Lightning Out is, advantages of force:recordData, component bundles, event propagation phases, and using Lightning:navigation to navigate between

Uploaded by

salesforce dc
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
569 views46 pages

30 Salesforce Lightning Developer Interview Questions

This document provides an overview of 30 Salesforce Lightning developer interview questions and answers related to Lightning components. It covers topics such as where Lightning components can be used, how to build them using two programming models, how to create Lightning record pages, options for record page assignment, using attributes to store values, accessing attribute values, calling controller actions from markup, interfaces for different use cases like getting record IDs and overriding standard actions, handling changes in attribute values, component and application events, using aura:method to pass values between parent and child components, defining field level security, what Lightning Out is, advantages of force:recordData, component bundles, event propagation phases, and using Lightning:navigation to navigate between

Uploaded by

salesforce dc
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 46

30 Salesforce Lightning Developer Interview Questions & Answers

1. Where we can use Lightning Components?


We can use Lightning Components in the following places:
 Drag-and-drop Components in the Lightning App Builder and Community
Builder.
 Add Lightning Components to Lightning Pages.
 Add Lightning Components to Lightning Experience Record Pages.
 Launch a Lightning Component as a Quick Action
 Override Standard Actions with Lightning Components
 Create Stand-Alone Apps

2. How do you build Lightning Components?


We can build Lightning Components using two programming models: the
Lightning Web Components model, and the original Aura Components model.
3. How can you create Lightning Record Pages in Salesforce, and what are the
different types?
We can make use of Lightning App Builder for creating Lightning Record Pages,
to create the following three types of pages:
 App Page
 Home Page
 Record Page

4. What options are there for Lightning Record Page assignment?


“Lightning Pages” can be assigned at three different levels:
 The org default
 App default – this overrides the assignment done at the org level
 App, record type, profile – this overrides the assignment done at org level and at
the App level.

5. What are attributes? What are their required parameters?


Attributes are variables, which are used to store values. We specify the Name,
Type, Default, Description, and Access in the attribute definition. Only Name and
Type are required parameters in the attribute definition, for example:
<aura: attribute name="firstName" type="String”/>

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”/>

7. How can you access a value from an attribute?


Use “Value Provide” which is denoted with the symbol “v”, for example:

<aura:attribute name="firstName" type="String"/>

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 component markup: &amp;lt;lightning:button label="SUBMIT"


onclick="{!c.doSubmit}"/&amp;gt;

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.&lt;strong&gt;attributeNameWhereValueChangeOcc
ured&lt;/strong&gt;}"action="{!c.doinit}"/&amp;>
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:

<aura:handler name="init" value="{!this}" action="{!c.doInitialization}"/

17. What are component events?


Component events are events which are fired by child components and handled by
the parent component. We can make use of this event when we need to pass a
value from a child component to parent component.
18. What are application events?
Application events can be fired from any component and can be handled by any
component. They do not require any kind of relationship between the components,
but these components must be a part of a single application.
19. Why would you use aura:method?
You can use a aura:method to pass value from a parent component controller to a
child component controller.
For example:
ParentComponent.cmp
<aura:component>
<c:ChildComp aura:id="ChildCompId"/>
</aura:component>

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.

24. What are the phases in component events propagation?


There are two phases in component event propagation.
1. Bubble Phase
2. Capture Phase

25. What are the phases in application events propagation?


1. Bubble Phase
2. Capture Phase
3. Default Phase

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.

27. What are bound and unbound expressions?


Bound and unbound expressions are used to perform data binding.
While calling a child component from a parent component, we can pass the value
to an attribute of a child component from a parent component attribute.
An example of a bound expression:
Parentcomp.cmp
<aura:component>

<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&gt>

<c:ChildComp childAttributeName="{#v.parentAttributeName}">;

</aura:component>

childAttributeName=“{#v.parentAttributeName}” is a Unbound expression,


changes to the value of the childAttributeName attribute in child component has
no effect on the value of parentAttributeName attribute in parent component and
vice versa.

28. What is Aura?


Aura is a framework design by Salesforce for creating UI components. It is an
open-source framework.
29. What is Lightning:navigation? How can we navigate using
Lightning:navigation?
Lightning:navigation is used to navigate to a given pageReference or to generate a
URL from a pageReference. To navigate, we need to define a PageReference
object.
Pagereference is a javascript object that references a page, providing a well-
defined structure that describes the page type and its corresponding values.
The following are supported features where we can navigate to:
 Lightning Component
 Knowledge Article
 Named Page
 Navigation Item Page
 Object Page
 Record Page
 Record Relationship Page
 Web Page
Example: To navigate to a component, we use the below syntax while defining
pagereference:

{
"type": "standard__component",
"attributes": {
"componentName": "c__MyLightningComponent
},
"state": {
"myAttr": "attrValue"
}
}

30. What is Lightning:isUrlAddressable interface?


If we are navigating to a component, then the component where we are navigating
to must implement lightning:isUrlAddressable interface to navigate there
successfully.

https://www.sfdc-lightning.com/p/salesforce-interview-questions.html

1) What is Lightning Component Framework and What is Aura Framework?

 Lightning Component framework is a UI framework for developing single


page applications for mobile and desktop devices.
It uses JavaScript on the client side and Apex on the server side.
Lightning Component framework makes developing apps that work on both
mobile and desktop devices far simpler than many other frameworks.
Lightning component Framework is based on Aura Framework.
Aura Framework is design by Salesforce which is open source framework for
creating ui components.

2) What is Lightning App Builder?


Lightning app builder is used to create lightning pages for Salesforce
Lightning experience and mobile apps.The Lightning App Builder is a point-and-
click tool.Lightning Pages are built using Lightning components which are
compact, configurable, and reusable elements that you can drag and drop into
regions of the page in the Lightning App Builder.

We can create different types of pages using lightning app builder,

1)App Page
2)Home Page
3)Record Page

3) What is the use of $A.enqueueAction(action) and how to call server side


action from client side?

$A.enqueueAction(action ) adds the server-side controller action to the queue of


actions to be executed.The actions are asynchronous and have callbacks.

4) What is Value provider and What is action provider in Salesforce


Lightning component?

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:

This value provider enable us to access value of component attribute in component


markup and javascript controller.

<aura:component>

<aura:attribute type="string" name="myfirstattribute" default="first text"/>

{!v.myfirstattribute}

</aura:component>
Action provider:

This enable us to handle actions,event,handlers for the component.

Ex:<aura:handler name="init" value="{!this}" action="{!c.doinit}"/>

In Javascript controller,

({

doinit:function(component, event, helper) {


// some operations here

})

5) What are Attributes in Salesforce Lightning component?


Attributes act like a variable to store different types of values.

6) What are collection types in Salesforce Lightning component?

1)Array

2)List

3)Map
4)Set
7) What is the use of interface force:hasRecordId and
flexipage:availableForAllPageTypes in Salesforce Lightning component?

By using force:hasRecordId interface in lightning component we can assigned the


id of the current record to lightning component. This interface adds an attribute
named "recordId" to the component. The type of attribute is string and has 18-
character Salesforce record ID.
To make our component available for record page and any other type of page, we
need to implement the interface flexipage:availableForAllPageTypes

8) What is the use of interface Lightning:actionOverride in Salesforce


Lightning component?
Lightning:actionOverride interface Enables a component to be used as an
override for a standard action. We can override the View,New, Edit, and Tab
standard actions on most standard and all custom components. The component
needs to implement the interface Lightning:actionOverride after which the
component appear in the Lightning Component Bundle menu of an object action
Override Properties panel.

9) What is the use of


interface flexipage:availableForRecordHome in Salesforce Lightning
component?
Interface flexipage:availableForRecordHome make the component available for
record pages only.

10) What is the use of interface force:appHostable in Salesforce Lightning


component?
Interface force:appHostable in component allow it to be used as a custom tab in
Lightning Experience or the Salesforce mobile app.

11) What is the difference between force:lightningQuickAction and


force:lightningQuickActionWithoutHeader in Salesforce Lightning
component?

Interface force:lightningQuickAction allow the component to be used as a


custom action in Lightning Experience or the Salesforce mobile app. Implementing
the force:lightningQuickAction in a component, component interface display in a
panel with standard action controls, such as a Cancel button.

Interface force:lightningQuickActionWithoutHeader allow the component to be


used as a custom action in Lightning Experience or the Salesforce mobile app.
Implementing the force:lightningQuickAction in a component, component
interface display in a panel without standard action controls like cancel button.
12) What is the use of aura:handler init event in Salesforce Lightning
component?
This is also called as the constructor of lightning component. The init event is
called once the component construction is over. As an example if I am creating a
simple registration page and I want to display some default text value after page
load in my input boxes I can do this by calling the javascript controller method and
setting some default value in the attributes.

Basic Syntax:

<aura:handler name="init" value="{!this}" action="{!c.doinit}"/>

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:

<aura:attribute name="Anyname" type="String" />


<aura:handler name="change" value="{!v.Anyname}" action="{!c.doinit}"/>
14) What is component event in Salesforce Lightning component?
Component Events are fired by the child components and handled by the parent
component. We require parent child relationship between two components if we
want to use component event between them for communication.

15) What is application event in Salesforce Lightning component?


Application event are the event handle by any component no matter what
relationship between them but they should be inside single application.

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.

17) Explain Bound and Unbound expressions in Salesforce Lightning


component?
We have two types of expression Bound expression and Unbound
expression which we use to perform data binding in lightning components.

Let see two example:

<c:ChildComp childAttributeName="{!v.parentAttributeName}" /> <!--Bound


Expression-->

childAttributeName="{!v.parentAttributeName}" is a bound expression. Any


change to the value of the childAttributeName attribute in child component also
changes the value of parentAttributeName attribute in parent component and
vice versa.

<c:ChildComp childAttributeName="{#v.parentAttributeName}" /> <!--


Unbound Expression-->

childAttributeName="{#v.parentAttributeName}" is a Unbound expression.


Any change to the value of the childAttributeName attribute in child component
has no effect on the value of parentAttributeName attribute in parent component
and vice versa.

18) What is Aura:method in Salesforce Lightning component?

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.

19) What is Lightning:overlayLibrary in Salesforce Lightning component?

To create a modal box we use Lightning:overlayLibrary.To


use Lightning:overlayLibrary in component we need to include
tag <lightning:overlayLibrary aura:id="overlayLib"/> in component, here
aura:id is unique local id. Modal has header,body and footer which are
customizable.

20) What is lightning:navigation in Salesforce Lightning component?

Lightning:navigation is used to navigate to a given pageReference.

Following are the supported type where we can navigate,

Lightning Component
Knowledge Article
Named Page
Navigation Item Page
Object Page
Record Page
Record Relationship Page
Web Page

21) Explain Lightning:recordForm in Salesforce Lightning component?

Using lightning:recordForm we can create forms to add, view, or update a


record. The field-level security and sharing are taken into consideration by this
component so user will only see the data they have access to.

22) Explain Lightning:recordEditForm in Salesforce Lightning component?


We use lightning:inputField inside the lightning:recordEditForm to create editable
fields.We can use lightning:outputField as well to display read-only
information. The field-level security and sharing are taken into consideration by
this component so user will only see the data they have access
to. lightning:recordEditForm supports the below features:

Display a record edit layout for editing a specified record.


Display a record create layout for creating a new record.
23) Explain Lightning:recordViewForm in Salesforce Lightning component ?

Lightning:recordViewForm use lightning:outputField and is used to display


information related to that record. The field-level security and sharing are taken
into consideration by this component so user will only see the data they have
access to.

24) Explain Standard controller of lightning component (force:recordData)?

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?

saveRecord() // It insert or update the loaded record.


deleteRecord() // It deletes the loaded record.
getNewRecord() // It loads a new record template that performs an insert when
data is saved.
reloadRecord() // It reruns the loading code to overwrite the current targetRecord
with the current attribute values.

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"

28) Explain parameters used with force:recordData in the below syntax ?

<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}"
/>

recordId specify the record on which processing needs to be done.


mode can be either EDIT or VIEW.(View for displaying records, edit for creating
or updating records)
layoutType specifies the layout (FULL or COMPACT).
fields specifies which fields in the record to query.
target attributes are attributes that force:recordData populates itself.

1) targetRecord is populated with the loaded record


2) targetFields is populated with the simplified view of the loaded record
3) targetError is populated with any errors

29) What parameter we use with force:recordData to handle record changes?

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.

Note: If force:recordData is in EDIT mode, targetRecord and targetFields are not


automatically updated.

30) What is Lightning out ?

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.

31) What is force:createRecord and what is the main advantage?


force:createRecord is an event that opens a page to create a record for specific
entity.

Sample syntax:

createRecord : function (component, event, helper) {


var createRecordEvent = $A.get("e.force:createRecord");
createRecordEvent.setParams({
"entityApiName": "ObjectApiName"
});
createRecordEvent.fire();
}

The main advantage is defaultFieldValues attribute inside setParams let us auto


populate value on fields inside record form.

recordEvent.setParams({
"entityApiName": "Account",
"defaultFieldValues":{
"Industry":"Apparel"
}
});

32) Explain force:editRecord event?

This event opens the record page specified by recordId to edit.

Syntax:

var editRecordEvent = $A.get("e.force:editRecord");


editRecordEvent.setParams({
"recordId": component.get("v.recordId")

});
editRecordEvent.fire();

33) What is Lightning:datatable in Salesforce Lightning component?

Lightning datatable is a table that displays columns of data, formatted according to


type.
Important attributes includes data, columns, and keyField attributes.The keyField
attribute is required for correct table behavior. It associates each row with a unique
identifier.

34) To form a container around a information related to single item or group


of item what we need to use in lightning component?

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:

<aura:handler name="init" value="{!this}" action="{!c.doinit}"/>

36) you are asked to execute some action when value change is detected in one
of the attribute what will you do?

We will use "change" Event.

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:

<aura:attribute name="Anyname" type="String" />


<aura:handler name="change" value="{!v.Anyname}" action="{!c.doinit}"/>

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?

Make use of Lightning:recordForm or Standard controller of lightning component


(force:recordData).

40) Lightning component is what type of framework?

It is a component based framework. It is an event driven architecture. It can called


as a MVCC framework which has two controller, one is client side and other is
server side.

41) How to use lightning component with Salesforce mobile app?


Make a tab for lightning component and include this tab in Salesforce1 mobile
navigation.

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.

43) When CRUD operations can be performed by form-based components


like lightning:recordForm, lightning:recordViewForm, lightning:recordEditF
orm taking field level security into consideration so what is the need
of force:recordData?

force:recordData is known as standard controller of lightning


component similar to we have standard controller in visualforce page. On its own,
force:recordData does not have inbuilt UI. We need to define the fields for taking
inputs. The lack of UI elements makes it a powerful addition. We can use it to
create highly customizable user interfaces beyond what the form-based
components provide. We can use custom components to display the data fetched
by force:recordData.

44) What are different component bundles in Salesforce Lightning


component?

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

1. Components contains markup for component or app.


2. The only required resource in a bundle.
3. Each bundle contains only one component or app resource.
Ex:

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.

45) What is NameSpace in Salesforce Lightning component?

The lightning component which we used are a part of NameSpace. NameSpace is


basically used to group components together. The default NameSpace is c. We can
create our own NameSpace for our organization. If we set the NameSpace for our
organization than this NameSpace is used for all of our Lightning components.

46) How can a Component or Application reference another Component?

Component or Application can reference another component using


<NameSpace:ComponentName> in its markup.

47) What is the difference between <lightning:input> and <ui:input> in


Salesforce Lightning component?

<lightning:input> are equipped with Lightning Design System Stylling whereas


<ui:input> is not equipped with Lightning Design System Styling.

48) Which interface needs to be implemented if we want our component to be


used in Community?

forceCommunity:availableForAllPageTypes

49) Explain the below javascript controller method?

Method:

({

addContact: function(component, event, helper) {


var action = component.get('c.insertContact');
action.setParams({

});
action.setCallback(this, function(response) {
var state = response.getState();
if (state === "SUCCESS") {
alert('Contact inserted successfully');
} else if (state === "INCOMPLETE") {

} else if (state === "ERROR") {

}
});
$A.enqueueAction(action);
}

)}

Explanation:

1) addContact is a Javascript controller method will be called from Component


markup.
2) Another Javascript controller method cannot called this "addContact" Method.
3) The parameters component in addContact is automatically provided by
framework as a parameters to Javascript controller method so that the markup
properties like attributes can be accessed using this.
4) The parameters event is automatically provided by framework as a parameters
to Javascript controller method so that the source from which
the addContact controller method was called can be determined.
5) The parameters helper is automatically provided by framework as a parameters
to Javascript controller method and using this the helper method can be called from
Javascript controller method.
6) var action = component.get('c.insertContact'); is calling the server method
which has the name insertContact.
7) action.setParams({ }); is optional parameter which is used to pass the apex
server method the required paramters.
8) action.setCallback received response as parameter using which the state of
response and response return can be determined.
9) $A.enqueueAction(action); adds the server-side controller action to the queue
of actions to be executed.The actions are asynchronous and have callbacks.
50) Explain the syntax to register the Component event?

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="registrationInChild" type="c:CompEvent"/>
<aura:attribute name="textMessage" type="String" default="Part from child
comp"/>
<lightning:button label="Click To Fire" onclick="{!c.doHandleEvent}"/>
</aura:component>

Component Event: (Name=CompEvent)

<aura:event type="COMPONENT" description="Event template" >

<aura:attribute name="storeMessage" type="String"/>

</aura:event>

51) How to get the above event i.e(Component event) in Javascript controller
of the component and how to fire it?

var cmpEvnt=component.getEvent("registrationInChild"); // Getting the event

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?

Parent Component: (Name=ParentComp)

<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);
}
})

53) Explain the syntax to register the Application event? Is it compulsory to


register the application event?

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 type="APPLICATION" description="Event template" >

<aura:attribute name="storeMessage" type="String"/>

</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);
}

})

56) What are the phases available with Component events?

1)Bubble phase (Movement is from bottom to top in case of bubble phase)


2)Capture phase (Movement is from top to bottom in case of capture phase)

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.

#salesforce lightning component interview questions#salesforce lightning


questions#interview questions on lightning aura components#salesforce lightning
interview questions and answers for experienced#salesforce interview questions
lightning#salesforce aura interview questions#lightning aura interview questions
57) Let say i have three components Bottom, Middle and Top as shown in
below image. Middle comp is the immediate parent of Bottom comp and Top
comp is the immediate parent of Middle comp. If i am firing
a Component event from bottom component and handling it in Middle and
Top component. What would be the behavior?

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 type="COMPONENT" description="Event template">

</aura:event>
Application:

<aura:application extends="force:slds" >


<c:TopComp/>
</aura:application>

OUTPUT:

From Middle component controller


From top component controller

#salesforce lightning component interview questions#salesforce lightning


questions#interview questions on lightning aura components#salesforce lightning
interview questions and answers for experienced#salesforce interview questions
lightning#salesforce aura interview questions#lightning aura interview questions

58) If in question 57 If i put phase="capture" in Top comp. How would be the


behavior?

TopComp.cmp:

<aura:component >
<c:MiddleComp/>
<aura:handler name="propagationEvent" event="c:CompEventforpropagation"
action="{!c.doHandleinTop}" phase="capture"/>

</aura:component>

OUTPUT:

From top component controller


From Middle component controller
#salesforce lightning component interview questions#salesforce lightning
questions#interview questions on lightning aura components#salesforce lightning
interview questions and answers for experienced#salesforce interview questions
lightning#salesforce aura interview questions#lightning aura interview questions

59) If in question 57 if i put phase="capture" in both Top and Middle comp.


How would be the behavior?

OUTPUT:

From top component controller


From Middle component controller

#salesforce lightning component interview questions#salesforce lightning


questions#interview questions on lightning aura components#salesforce lightning
interview questions and answers for experienced#salesforce interview questions
lightning#salesforce aura interview questions#lightning aura interview questions

60) If in question 57 if i put phase="capture" in Top comp


and phase="bubble" in Middle comp.
How would be the behavior?

OUTPUT:

From top component controller


From Middle component controller

61) If in question 57 if i put phase="bubble" in Top comp and no phase in


Middle comp.
How would be the behavior?

OUTPUT:

From Middle component controller


From top component controller

62) If in question 57 if i put phase="bubble" in Middle comp and no phase in


Top comp.
How would be the behavior?

OUTPUT:

From Middle component controller


From top component controller

63) If in question 57 if i put phase="bubble" in both Middle comp and Top


comp.
How would be the behavior?

OUTPUT:

From Middle component controller


From top component controller

NOTE:

1)Bubble phase will always moves from bottom to top.

2) Capture phase will move from top to bottom


#salesforce lightning component interview questions#salesforce lightning
questions#interview questions on lightning aura components#salesforce lightning
interview questions and answers for experienced#salesforce interview questions
lightning#salesforce aura interview questions#lightning aura interview questions

64) What are the phases available with Application events?

1)Bubble phase
2)Capture phase
3)Default phase

Top 20 Salesforce Lightning Interview Question and Answers

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.

2) Can We Make A Lightning Component That Shows Up In Both The Mobile


And The Desktop User Interfaces ?

We can use Lightning Components directly in Lightning Experience, the


Salesforce1 Mobile app, template-based communities, and custom standalone apps.
Additionally, we can include Lightning components in a Visualforce page, that
allowing us to use them in Salesforce Classic, Console, and Visualforce-based
communities.

3) Is Lightning An Mvc Framework ?

No, it’s a component-based framework.

4) Which Parts Of Lightning Components Are Server-side And Which Are


Client-side?

Lightning Components are use JavaScript on the client side and Apex on the server
side.

5) Can We Make One Component Inherit Styles/css From A Parent


Component, Or Must We Always Define It In The Component ?

Yes, we can inherit styles from parent. there is no need to always defined in the
component.

For more info at salesforce online training Hyderabad

6) What Is The Use Of The Aura: method Tag in Lightning?

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 ?

Yes, we can Include one lightning component to another lightning component

8) Is There Any Limit On How Many Components To Have In One


Application?

there is no limit.

9) Is Lightning Components Replacing Visualforce?

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.

11) Do We Need A Namespace To Develop Lightning Components?

No. Lightning Components used to require a namespace, but that is no longer a


requirement.

12) What Are The Tools Included In Lightning?


Lightning Component Framework — Components and extensions that allow you to
build reusable components, customize the Salesforce1 Mobile App, and build
standalone apps.

 Lightning App Builder — A new UI tool that lets you build apps lightning
fast, using components provided by Salesforce and platform developers.

 Lightning Connect — An integration tool that makes it easier for your


Force.com app to consume data from any external source that conforms to the
OData spec.

 Lightning Process Builder — A UI tool for visualizing and creating


automated business processes.

 Lightning Schema Builder — A UI tool for viewing and creating objects,


fields, and relationships.

13) What Is Difference Between Visualforce Components And Lightning


Components?

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.

14) Does Lightning Work with Visualforce?

Yes Lightning work with Visualforce.


15) Are There Any Css (styles) Provided by Salesforce.com as Part of the
Supported Lightning Components?

Yes. Salesforce Lightning Design System.

16) Are Lightning Components Intended Only For Mobile Apps?

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.

17) What Are The Advantages Of Lightning?

The benefits include an out-of-the-box set of components, event-driven


architecture, and a framework optimized for performance.

Out-of-the-Box Component Set -: Comes with an out-of-the-box set of


components to kick start building apps. You don’t have to spend your time
optimizing your apps for different devices as the components take care of that for
you.

Rich component ecosystem-: Create business-ready components and make them


available in Salesforce1, Lightning Experience, and Communities.

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

Faster development –: Empowers teams to work faster with out-of-the-box


components that function seamlessly with desktop and mobile devices.

Device-aware and cross browser compatibility –: responsive design supports the


latest in browser technology such as HTML5, CSS3, and touch events.

18) Can We Integrate Lightning Components With Another Framework, Such


As Angular?

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.

19) Can We Include External JavaScript/css Libraries In Components?

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).

20) What Happens With Existing Visualforce Pages In Lightning Experience?

They’ll continue to be supported in the current UI and Lightning Experience.

21) How Can We Deploy Components To Production Org?


We can deploy component by using managed packages, Force.com IDE, Force.com
Migration Tool or Change Sets.

22) What Is Lightning Experience?

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.

2. Lightning It is a JavaScript framework that comes along with standard


Component components and enables the developers to create components wh
Framework be reused for standalone applications. These apps are built by
customization of Lightning experience, template-based communi
well as mobile apps created with Salesforce1.

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.

5. Lightning Start with development with a set of 70 + partner components as


Exchange section of AppExchange.
Suggested reading =>> Salesforce Lightning Tutorial
Q #2) What are the components in the Lightning component framework?
Answer: The components act as functional units of the Lightning component
framework. A reusable, modular section of UI is encapsulated within the
components. They can range from a single line of text up to the entire application
in terms of granularity.
Q #3) Where to use Lightning Components?
Answer: The Lightning components can be used in the following ways:
 Drag-and-drop components are meant for the Lightning App Builder and
Community Builder.
 Add Lightning Components for Lightning Pages.
 Add Lightning Components for Lightning Experience Record Pages.
 Launch a Quick-action Lightning Component.
 Overrule the Lightning Component’s standard actions.
 Create custom applications
Q #4) What are the components bundles used in the Lightning component?
Answer: The component bundles are enlisted in the below table:
Sl. Name of Component
Description
No. Bundle

1 Component This contains the mark up.

2 Controller This handles the events on the client side.

3 Helper The developer can write the common logic inside helper used b
different controller methods, avoiding any sort of repetition

4 Style This is about the style of the component.

5 Documentation This records the component’s use.

6 Renderer This contains the default rendering behaviour of a component.

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.

Q #34) Why Lightning:isUrlAddressable interface is used?


Answer: The lightning:isUrlAddressable interface is used when navigating to the
component and also when the component to be navigated implements this
interface.
Q #35) How to find data changes using data handlers?
Answer: You can configure a component for invoking a change handler when the
value of the attributes in one of the many components changes.

Q #36) What are component events?


Answer: A component event is fired from the instance of a component. It can be
handled by the event that fired the event or by the component in the containment
hierarchy, receiving the event. There are capture and bubble phases for the
propagation of component events.
Q #37) What are application events?
Answer: An application event is fired from an instance of a component. It follows
a publish-subscribe model. The components that provide a handler for the event are
notified. The phases supported by the framework are capture, bubble, and default
phase for the propagation of application events. The capture and bubble phases
have similarities with DOM handling patterns.
Q #38) What are the phases in component events propagation?
Answer: The two phases are:
 Bubble phase
 Capture phase
Q #39) What is Lightning Out?
Answer: Lightning Out is a powerful and flexible feature that allows you to embed
the Lightning web components on any web page. While using this, you do not need
to deal with authentication or even configure a connected app, and this simplifies
some of the details when used with Visualforce.

You might also like