Salesforce Lightning Interview Questions
Salesforce Lightning Interview Questions
a. Application Event � Scope of this event is throughout the lightning App and any
component which has registered for this event would get a notification.
b. Component Event� Scope of this event is within itself or the parent component of
this event, all the components declared within the parent component would get
notified of this event.
c. System Event- these are the events fired by Salesforce�s system during the
lifecycle of the lightning app.
2. What are the basic differences between Application Event and Component Event?
Component events are used to do communication between child and parent. They use
bubbling and capture same as used in DOM events. A change in a child component can
be communicated to the parent component via component event.
Application events are used to communicate any change in the component to a broader
audience. Any component who has registered for this event will get a notified.
To use Component Event API we use the below syntax
Application events are best used for something that should be handled at the
application level, such as navigating to a specific record. Application events
allow communication between components that are in separate parts of the
application and have no direct containment relationship.
A Lightning component can be embed in any webpage using a very powerful and
flexible feature, Lighting out. When used with Visualforce some complexity becomes
simpler.
Lightning component can be added to Visualforce page in three steps:
1. We have to first Add the Lightning Components for Visualforce JavaScript library
to your targetted Visualforce page using the tag.
2. Next we have to create and refer a Lightning app which is used to the component
dependencies.
3. Lastly we need to write a JavaScript function which will finally create the the
component on the page using $Lightning.createComponent()
7. How can we call child component controller method from the parent component
controller method?
Controller
({
publicmethod: function(cmp, event) {
var params = event.getParam(�arguments�);
if (params) {
var message = params. str;
console.log(�message: � + message);
return message;
}
}
})
FLS and CRUD are not automatically enforced in the lightning component whenever any
object is referenced in the Apex Controller and the component will display the
fields and records for which the users do not have access. Therefore we should
manually enforce the FLS and CRUD in the Apex Controller, or we should try to use
Lightning Data service wherever possible because it takes care of FLS and CRUD for
us.
10. How can we use Lightning Components with the Salesforce1 Mobile App ?
For this purpose we need to first make a lightning tab which points to the
lightning component we created and then we have to include that tab in the
salesforc1 Mobile Navigation select list and the newly created tab to it.
11. Can we make a Lightning Component that shows up in both the mobile and the
desktop user interfaces?
13. Which parts of Lightning Components are server-side and which are client-side ?
Lightning components have two types of controller, one which uses javascript and
responds to the event occurring in the components at client side and the second
controller which is an apex class. Method of apex controller are accessed by the
JavaScript controller methods asynchronously.
14. Can we make one component inherit styles/CSS from a parent component, or must
we always define it in the component ?
Child component inherits the CSS from its aren�t we do not need to specify it for
each component
17. Is there any limit on how many component to have in one Application?
19. What is Aura? Why do we use the aura: namespace in the code?
Aura is a UI framework for developing dynamic web apps for mobile and desktop
devices. Aura provides a scalable long-lived lifecycle to support building apps
engineered for growth.
Aura supports partitioned multi-tier component development that bridges the client
and server. It uses JavaScript on the client side and Java on the server side.
You can have namespace in your org but it is not necessary to have a namespace to
develop lightning component.
Visualforce page is created keeping page as the center of the application and most
of its calculation is performed at the server side. Lightning component on the
other hand are created using the component based framework, most of the
calculations are performed at the client side and makes the more dynamic and
provide rich customer experience, also lightning component are build using mobile
first approach.
24. Are there any CSS (styles) provided by salesforce.com as part of the supported
Lightning Components ?
Salesforce has provided lightning design system as the default css to be used with
Lightning component.
Although lightning framework creates component keeping mobile first approach, but
its responsive design helps in providing the same experience over the desktop
without writing separate lines of code
There are many advantages of using lightning like its out of the box component set
which enables the fast paced creation of new apps, its event driven architecture
which enables the easy decoupling between the components. Device awareness, cross
browser compatibility and framework optimized for the performance.
27. Can we integrate Lightning components with another framework, such as Angular?
Most of the Visualforce page can be easily converted to lightning experience, but
they are still supported by the salesforce and are not required to be converted
30. Where we can display lightning component?
31. Do I always create an app bundle first when develop lightning component ?
Lightning component can be deployed to the production via change sets, force.com
IDE, Managed Package.
�Event� and �action� attribute are same as the component event handling, it is just
that we do not include �name� attribute to handle the application event.
Lightning bundles must be under a top-level folder that�s named aura. Each bundle
must have its own subfolder under the aura folder.
A bundle doesn�t have a suffix but definition files can have one of these suffixes
Suffix Component Type
Suffix
Component Type
.app
Application
.cmp
Component
.design
Design
.evt
Event
.intf
Interface
.js
Controller, Helper, or Renderer
.svg
SVG image
.css
Style
.auradoc
Documentation
.tokens
Tokens collection
They are same as member variable in apex classes, they are typed fields and are
instance of a component. Attribute helps in making component more dynamic.
All attributes have a name and a type can be marked required by specifying
�required=true�and can also have a default value. It has a naming rule as well:
42. How to register, fire and handle a component and application event?
compEvent.fire();
43. Let�s say that you have an app myApp.app that contains a component myCmp.cmp
with a ui:button component. During initialization, the init() event is fired in
what order?
The AuraEnabled annotation provides support for Apex methods and properties to be
used with the Lightning Component framework.
The AuraEnabled annotation is overloaded, and is used for two separate and distinct
purposes.
1. Use @AuraEnabled on Apex class static methods to make them accessible as remote
controller actions in your Lightning components.
2. Use @AuraEnabled on Apex instance methods and properties to make them
serializable when an instance of the class is returned as data from a server-side
action.
This adds namespacing to CSS and helps prevent one component�s CSS from blowing
away another component�s styling.
47. What are the different ways to conditionally display markup, and what is the
preferred approach?
It lets you reference images, style sheets, and JavaScript code you�ve uploaded in
static resources.
48. Let�s say you have several buttons that reuse the same onclick handler. How
will you retrieve the name of the button that fired the event?
49. What are the names of interfaces that are added to a Lightning component to
allow it to be used as custom tabs, and to be used in Lightning and Community
builder?
Private: Available within the component, app, interface, event, or method and can�t
be referenced outside the resource. This value can only be used for or .Marking an
attribute as private makes it easier to refactor the attribute in the future as the
attribute can only be used within the resource.
Accessing a private attribute returns undefined unless you reference it from the
component in which it�s declared. You can�t access a private attribute from a sub-
component that extends the component containing the private attribute.
Public: Available within your org only. This is the default access value.
54. What are Local and Global ids with respect to lightning component?
Component IDs
A component has two types of IDs: a local ID and a global ID. You can retrieve a
component using its local ID in your JavaScript code. A global ID can be useful to
differentiate between multiple instances of a component or for debugging purposes.
Local IDs
A local ID is an ID that is only scoped to the component. A local ID is often
unique but it�s not required to be unique.
Create a local ID by using the aura:id attribute. For example:
Find the button component by calling cmp.find(�button1�) in your client-side
controller, where cmp is a reference to the component containing the button.
Global IDs
Every component has a unique globalId, which is the generated runtime-unique ID of
the component instance. A global ID (1) is not guaranteed to be the same beyond the
lifetime of a component, so it should never be relied on. A global ID can be useful
to differentiate between multiple instances of a component or for debugging
purposes.
FlexiPage
Represents the metadata associated with a Lightning page. A Lightning page
represents a customizable screen made up of regions containing Lightning
components.
A Lightning page region can contain upto 25 components.
Lightning pages are referred as FlexiPages in API and referred as Lightning pages
elsewhere in SFDC documentation
56. How to make quick lightning action?
$globalID
$Browser
$Label
$Locale
$Resource
Lightning Connect
Lightning Component Framework
Lightning Schema Builder
Lightning Process Builder
Lightning App Builder
Component event: Component event is used to communicate with parent component using
bubble event.
Lightning component can communicate using event communication framework. Read more
about component communication patterns
helper.js: JavaScript functions that can be called from any JavaScript code in a
component�s bundle
design: File required for components used in Lightning App Builder, Lightning
pages, or Community Builder.
SVG: Custom icon resource for components used in the Lightning App Builder or
Community Builder.
9. What is aura:attribute
Attributes are like member variables on a class in Apex. They are typed fields that
are set on a specific instance of a component, and can be referenced from within
the component�s markup using an expression syntax.
lightning: and ui: are two namespaces for core lightning component. The lightning
namespace components are optimized for common use cases.