Skip to main content

Commonly asked Lightning Developer Interview Questions & Answers

1. Where can we 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, Access in the attribute definition. Only Name and Type are required parameters in the attribute definition, for example:

1
<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:

1
&lt;aura:attribute name="firstName" type="String"/&gt;

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:

1
2
3
4
5
6
7
8
9
10
11
12
13
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:

1
&lt;aura:handler name="change"value="{!v.&lt;strong&gt;attributeNameWhereValueChangeOccured&lt;/strong&gt;}"action="{!c.doinit}"/&amp;gt;

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:

1
&lt;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

1
2
3
&lt;aura:component&gt;
 &lt;c:ChildComp aura:id="ChildCompId"/&gt;
&lt;/aura:component&gt;

INSIDE ParentComponentController.js

1
2
var childCompId=component.find("ChildCompId");
var res=childComponent.chilCompMethod("From parent");

INSIDE ChildComponent.cmp

1
2
3
4
5
&lt;aura:component&gt;
 &lt;aura:method name="chilCompMethod" action="{!c.doAction}"&gt;
    &lt;aura:attribute name="receiveValueFromParent" type="String" /&gt;
&lt;/aura:method&gt;
&lt;/aura:component&gt;

INSIDE ChildComponentController.js

1
2
3
4
5
6
7
8
({
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

1
2
3
4
5
&lt;aura:component&gt;
 
&lt;c:ChildComp childAttributeName="{!v.parentAttributeName}" /&gt;
 
&lt;/aura:component&gt;

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:

Parentcomp.cmp

1
2
3
4
5
&lt;aura:component&gt;
 
&lt;c:ChildComp childAttributeName="{#v.parentAttributeName}" /&gt;
 
&lt;/aura:component&gt;

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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
{
 
"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.

1
2

Comments

Popular posts from this blog

Get started with Simple Lightning Web Component(Bike Card)

Lightning web component HTML files all include the template tag. The template tag contains the HTML that defines the structure of your component. Let’s look at the HTML for a simplified version of the component. Paste the following into app.html (replacing any existing HTML in the file). bikeCard.html < template > < div id = "waiting" if : false = { ready } > Loading.. </ div > < div id = "dispaly" if : true = { ready } > < div > Name: {name} </ div > < div > Description: {description} </ div > < div > Category: {category} </ div > < div > Material: {material} </ div > < div > Price: {price} </ div > < div >< img src = { pictureURL } /></ div > </ div > </ template > The identifiers in the curly braces {} are bound to the fields of the same name in the corresponding JavaScript class. Here’s a JavaScript file to s...

Disable Document Download in Salesforce

Disable downloads for certain users based on the name of the file uploaded to Salesforce. We can use the following example code inside of a Apex class. This code essentially prevents files whose file name starts off with Kaipu- from being downloaded by anyone whose user role’s developer name is not Kaipu_Sales. Modify this code to suit your own purpose. Based on Role: public class ContentDownloadHandlerFactoryImpl implements Sfc.ContentDownloadHandlerFactory {    public Sfc.ContentDownloadHandler getContentDownloadHandler(List<ID> ids, Sfc.ContentDownloadContext context) {      // See if the user has the Kaipu Sales role (based on developer name field).      Boolean isSecretUser = [        SELECT Id        FROM UserRole        WHERE ID = :UserInfo.getUserRoleId()          AND DeveloperName = ' Kaip...