Aura Myla
Aura Myla
Aura-Lightning
__________________________________________________________________-
setup
|-----Adminster
|--------Domain Management
|--------------MyDomain
b. Check availabilty
c. Register
5. Deploy to users so that users can login using this domain url
2. create package : This is optional ,but if you want to provide lightning apps to
====================================================================================
Lishtning Application
====================================================================================
UserName
|----Developer Console
|---File
|--Lightning App
1
|---App name
Ex: <aura:application>
</aura:applicaiton>
1. Every lightning application will start and end with <aura:applicaiton> component .
2. Arributes :
a.access :
of a namespace.
b.controller:
1.This is will take name of the Apex class whose functionalities are used
in this application..
c.extends:
2
d.extensible:
e. implements:
1.It will take the list of interfaces that the application want to
implements.
=====================================================================================
==
Component :
=====================================================================================
==
1.<aura:component> :
Syntax:
<aura:component>
</aura:component>
d.Attributes :
3
1.access :
of a namespace.
2.controller :
a.This is will take name of the Apex class whose functionalities are
3. extends :
4. extensible:
5. implements :
a.It will take the list of interfaces that the component want to implements.
Ex : implements ="one,two,three"
4
UserName
|---Developer console
|--File
|--Lightning Componet
|---Component Name
Example : capital1.cmp
<aura:component >
</aura:component>
1. if the you have created any namespace then is should be called using namespace
<capitalinfosol : example1>
2. if you dont have the namespace then it will be called using defualt namespace i.e c
<c: example1>
5
<aura:application >
<c:capital1></c:capital1>
</aura:application>
=====================================================================================
=======================
=====================================================================================
=======================
<aura:component >
</aura:component>
<aura:component >
<div>
Ameerpet <br/>
SRNagar <br/>
Hyd <br/>
TG <br/>
</div>
</aura:component>
<c:student />
6
<c:studentAddress />
</aura:application>
=====================================================================================
==========
=====================================================================================
=========
<aura:component >
</aura:component>
.THIS {
background-color:yellow;
padding-top : 40px;
padding-left :40px;
.THIS.red {
background-color: red;
7
.THIS.blue {
background-color: blue;
.THIS.green {
background-color: green;
3. Application : capital3
<aura: application>
<c:csscomp> </c:csscomp>
<aura :application>
=====================================================================================
================
=====================================================================================
==============
<aura:attribute>
Attributes :
a. access :Indicates whether the attribute can be used outside of its own namespace.
8
d. defualt : Value that should be assingned to the attribue if no values are assigned to it
f. required : Specified wheather attribute value need to be required to run this component.
Example :
Examples :
<aura:component >
</aura:component>
Ex : {! v.empName }
Ex :{! v.salary}
Ex :{! v.city}
Ex :{! v.phone}
9
<aura:component >
<div>
</div>
</aura:component>
.THIS {
padding-top: 40px;
padding-left:80px;
color: blue;
<aura:application >
</aura:application>
=====================================================================================
===============
<aura:handler>
a. This component is used to intialize the values /attributes in the component /application
10
b. This event istriggered on app or component for initialization.
c. This event is automatically fired when an app or component is has initializations prior
to rendering.
Attributes :
c. action :The client-side controller action that handles the value change.
Syntax :
Syntax of controller :
({
methodname :function(component){
})
component.get("v.attributename");
component.set("v.attribute" ,value);
=====================================================================================
==========
Example 1:
11
a. Create a component with three attributes aval,bval,cval
Calculate.cmp
<aura:component >
<div>
<h2>BVal :{!v.bval}</h2>
<h2>CVal :{!v.cval}</h2>
</div>
</aura:component>
.THIS {
padding-left :80px;
padding-top :80px;
color :green;
c. create a clientside controller by clicking controller button on right side menu wizard
calculate.js
({
add : function(component) {
var aval=component.get("v.aval");
12
var bval=component.get("v.bval");
var cval=aval+bval;
component.set("v.cval",cval);
})
<aura:application >
</aura:application>
Examples 2 :
empcomp
<aura:component >
</aura:component>
({
show : function(component) {
})
c create a Application :
13
<aura:application >
<c:empcomp> </c:custom1>
</aura:application>
Example 3:
<aura:component >
<div>
Intrest:{! v.intrest}
</aura:component>
.THIS {
padding-left :80px;
padding-top :80px;
color :green;
14
c. create a clinet side controller
({
calcualte : function(component) {
component.set("v.empName","satish myla");
var amount=component.get("v.amount");
var years=component.get("v.years");
var rate=component.get("v.rate");
var intrest=amount*years*rate/100;
component.set("v.intrest",intrest);
})
d. create an application
<aura:application >
</aura:application>
15
=====================================================================================
========================
=====================================================================================
======================
<aura:iteration> :
1. This component is used to display collecton elements by iterating over every elemet
Attribues :
var : Required. The variable name to use for each item inside the iteration.
Example 1:
collection1:
<aura:component>
<h1>Items : {!item}</h1>
</aura:iteration>
</aura:component>
<aura:application>
<c:collection1 />
</aura:application>
16
Example 2:
<aura:component >
</aura:iteration>
</aura:component>
2. Application :
<aura:application >
<c:collection2></c:collection2>
</aura:application>
Example 3:
<aura:component >
</aura:iteration>
</aura:component>
({
callme : function(component) {
17
var names=['Ram','Kiran','Hari'];
component.set("v.names",names);
})
<aura:application >
<c:collection3></c:collection3>
</aura:application>
=====================================================================================
======
<aura:component >
</aura:component>
2. create a application
<aura:application >
<c:uicomponent1 />
</aura:application>
18
-------------------------------------------------------------------------------------------
Q:: Setting and getting values of component using id in the controller method
component.find("idname").get("v.value");
component.find("idname").set("v.value",value);
----------------------------------------------------------------------------------------------
Example 1:
<aura:component >
</aura:component>
2. create a controller :
({
callme : function(component) {
var name=component.find("name").get("v.value");
component.find("myname").set("v.value",name);
})
3. Create a application :
<aura:application >
<c:uicomponent2 />
</aura:application>
19
Example 2 :
<aura:component >
</aura:component>
Controller :
({
outName.set("v.value", fullName);
})
Application :
<aura:application >
<c:comp5></c:comp5>
</aura:application>
20
=====================================================================================
========
Example 9 :set the attribute values from the UI components based on the events on componets
<aura:component >
</aura:component>
Application :
<aura:application >
<c:comp6></c:comp6>
</aura:application>
=====================================================================================
=====
<aura:component >
21
<ui:inputSelect>
<ui:inputSelectOption text="Red"/>
<ui:inputSelectOption text="Blue"/>
</ui:inputSelect>
</aura:component>
Application :
<aura:application>
<c:compPick></c:compPick>
</aura:application>
=====================================================================================
=======
<aura:component >
<aura:if isTrue="{!v.edit}">
<ui:button label="Edit"/>
<aura:set attribute="else">
No button
</aura:set>
</aura:if>
</aura:component>
22
Application :
<aura:application>
<c:comp8></c:comp8>
</aura:application>
=====================================================================================
=====
1. Every method of the apex which we want to invoke in the lightning should obey the following
rules
2. If you want to the apex class in the lightning component / application it should be define as a
controller
3.When we want to invoke the reffer to the server-side controller method from the client side
controller
method
Syntax :
component.get("c.methodName");
var mycall=component.get("c.methodName");
myCall.setcallback(this, function(response) {
23
logic
});
var state=response.getStatus();
6.Every apex method invocation from the controller javascript is asynchronous so we need to
$A.enqueueAction(action);
Example :
@AuraEnabled
<aura:component controller="AuraExample1">
</aura:component>
24
({
show : function(component) {
var action=component.get("c.getName");
action.setCallback(this, function(response){
component.set("v.empName",
response.getReturnValue());
});
$A.enqueueAction(action);
})
4. create a application
<aura:application >
<c:apexcall />
</aura:application>
=====================================================================================
==========
Example 14: Reading a list account records from Sobject and display in Lightning
25
@AuraEnabled
return accs;
Component : Custom5 :
<aura:component controller="AuraExample2">
<p>{!a.Name} : {!a.Id}</p>
</aura:iteration>
</aura:component>
Controller:
({
getAccs: function(cmp){
action.setCallback(this, function(response){
cmp.set("v.Accounts", response.getReturnValue());
26
}
});
$A.enqueueAction(action);
})
Application :
<aura:application >
<c:custom5></c:custom5>
</aura:application>
=====================================================================================
=========
-------------------------------------------------------------------
<aura:component>
<aura:set attribute="body">
<!--START BODY-->
<div>Body part</div>
<!--END BODY-->
</aura:set>
</aura:component>
App6.app
<aura:application >
<c:bodyAttribute></c:bodyAttribute>
</aura:application>
27
-------------------------------------------------------------------------
-------------------------------------------------------------------------
facetHeader.cmp
<aura:component>
<div>
<span class="header">{!v.header}</span><br/>
<span class="body">{!v.body}</span>
</div>
</aura:component>
facetHeaders.cmp
<aura:component>
<c:facetHeader>
Nice body!
<aura:set attribute="header">
Hello Header!
</aura:set>
</c:facetHeader>
</aura:component>
Application
<aura:application >
<c:facetHeaders></c:facetHeaders>
</aura:application>
28
=====================================================================================
===
<aura:dependency resource="ui:button"/>
</aura:application>
VF Page :
<apex:page>
<apex:includeLightning />
<script>
$Lightning.use("c:app15", function() {
"lightning",function(cmp) {});
});
</script>
</apex:page>
29
====================================================================================
2.Lishtning Application
====================================================================================
UserName
|----Developer Console
|---File
|--Lightning App
|---App name
Ex: <aura:application>
</aura:applicaiton>
1. Every lightning application will start and end with <aura:applicaiton> component .
2. Arributes :
a.access :
of a namespace.
30
b.controller:
1.This is will take name of the Apex class whose functionalities are used
in this application..
c.extends:
d.extensible:
e. implements:
1.It will take the list of interfaces that the application want to
implements.
=====================================================================================
==
3.Component :
=====================================================================================
==
1.<aura:component> :
31
a. Components are the functional units of Aura,
Syntax:
<aura:component>
</aura:component>
d.Attributes :
1.access :
of a namespace.
2.controller :
a.This is will take name of the Apex class whose functionalities are
3. extends :
4. extensible:
32
b.possible values : true /false
5. implements :
a.It will take the list of interfaces that the component want to implements.
Ex : implements ="one,two,three"
UserName
|---Developer console
|--File
|--Lightning Componet
|---Component Name
Example : capital1.cmp
<aura:component >
</aura:component>
1. if the you have created any namespace then is should be called using namespace
33
<namespace: componentName >
<capitalinfosol : example1>
2. if you dont have the namespace then it will be called using defualt namespace i.e c
<c: example1>
<aura:application >
<c:capital1></c:capital1>
</aura:application>
=====================================================================================
=======================
=====================================================================================
=======================
<aura:component >
</aura:component>
<aura:component >
34
<div>
Ameerpet <br/>
SRNagar <br/>
Hyd <br/>
TG <br/>
</div>
</aura:component>
<c:student />
<c:studentAddress />
</aura:application>
=====================================================================================
==========
=====================================================================================
=========
<aura:component >
</aura:component>
35
:Then it creates csscomp.css
.THIS {
background-color:yellow;
padding-top : 40px;
padding-left :40px;
.THIS.red {
background-color: red;
.THIS.blue {
background-color: blue;
.THIS.green {
background-color: green;
3. Application : capital3
<aura: application>
<c:csscomp> </c:csscomp>
<aura :application>
=====================================================================================
================
36
=====================================================================================
==============
<aura:attribute>
Attributes :
a. access :Indicates whether the attribute can be used outside of its own namespace.
d. defualt : Value that should be assingned to the attribue if no values are assigned to it
f. required : Specified wheather attribute value need to be required to run this component.
Example :
Examples :
<aura:component >
</aura:component>
37
How to read the values of attributes in the component / appliation
Ex : {! v.empName }
Ex :{! v.salary}
Ex :{! v.city}
Ex :{! v.phone}
<aura:component >
<div>
</div>
</aura:component>
.THIS {
padding-top: 40px;
padding-left:80px;
color: blue;
38
}
<aura:application >
</aura:application>
4..LightningHandler.txt
<aura:handler>
a. This component is used to intialize the values /attributes in the component /application
c. This event is automatically fired when an app or component is has initializations prior to
rendering. T
Attributes :
c. action :The client-side controller action that handles the value change.
Syntax :
Syntax of controller :
({
methodname :function(component){
39
})
component.get("v.attributename");
component.set("v.attribute" ,value);
=====================================================================================
=======================
Example 1:
=====================================================================================
=========================
Calculate.cmp
<aura:component >
<div>
<h2>BVal :{!v.bval}</h2>
<h2>CVal :{!v.cval}</h2>
</div>
</aura:component>
40
b. create style for the component :
.THIS {
padding-left :80px;
padding-top :80px;
color :green;
c. create a clientside controller by clicking controller button on right side menu wizard
calculate.js
({
add : function(component) {
var aval=component.get("v.aval");
var bval=component.get("v.bval");
var cval=aval+bval;
component.set("v.cval",cval);
})
<aura:application >
</aura:application>
=====================================================================================
===============
Examples 2 :
=====================================================================================
================
41
a. create a new custom component :
empcomp
<aura:component >
</aura:component>
({
show : function(component) {
})
c create a Application :
<aura:application >
<c:empcomp> </c:custom1>
</aura:application>
=====================================================================================
=================
Example 3:
=====================================================================================
==================
<aura:component >
42
<aura:attribute name="amount" type="decimal" />
<div>
Intrest:{! v.intrest}
</aura:component>
.THIS {
padding-left :80px;
padding-top :80px;
color :green;
({
calcualte : function(component) {
component.set("v.empName","satish myla");
var amount=component.get("v.amount");
43
var years=component.get("v.years");
var rate=component.get("v.rate");
var intrest=amount*years*rate/100;
component.set("v.intrest",intrest);
})
d. create an application
<aura:application >
</aura:application>
5 .LightningIterator
_____________________________________________________________________________________
=====================================================================================
======================
<aura:iteration> :
1. This component is used to display collecton elements by iterating over every elemet
Attribues :
44
var : Required. The variable name to use for each item inside the iteration.
Example 1:
collection1:
<aura:component>
<h1>Items : {!item}</h1>
</aura:iteration>
</aura:component>
<aura:application>
<c:collection1 />
</aura:application>
Example 2:
<aura:component >
</aura:iteration>
</aura:component>
45
2. Application :
<aura:application >
<c:collection2></c:collection2>
</aura:application>
Example 3:
<aura:component >
</aura:iteration>
</aura:component>
({
callme : function(component) {
var names=['Ram','Kiran','Hari'];
component.set("v.names",names);
})
<aura:application >
<c:collection3></c:collection3>
</aura:application>
46
6 .LightningUIExamples
<aura:component >
</aura:component>
2. create a application
<aura:application >
<c:uicomponent1 />
</aura:application>
-------------------------------------------------------------------------------------------
Q:: Setting and getting values of component using id in the controller method
component.find("idname").get("v.value");
component.find("idname").set("v.value",value);
47
----------------------------------------------------------------------------------------------
Example 1:
<aura:component >
</aura:component>
2. create a controller :
({
callme : function(component) {
var name=component.find("name").get("v.value");
component.find("myname").set("v.value",name);
})
3. Create a application :
<aura:application >
<c:uicomponent2 />
</aura:application>
Example 2 :
<aura:component >
48
<ui:inputText label="Name" aura:id="name" placeholder="First, Last"/>
</aura:component>
Controller :
({
outName.set("v.value", fullName);
})
Application :
<aura:application >
<c:comp5></c:comp5>
</aura:application>
=====================================================================================
========
Example 9 :set the attribute values from the UI components based on the events on componets
<aura:component >
49
<ui:inputText label="First Name" value="{!v.first}" updateOn="keyup"/>
</aura:component>
Application :
<aura:application >
<c:comp6></c:comp6>
</aura:application>
=====================================================================================
=====
<aura:component >
<ui:inputSelect>
<ui:inputSelectOption text="Red"/>
<ui:inputSelectOption text="Blue"/>
</ui:inputSelect>
</aura:component>
50
Application :
<aura:application>
<c:compPick></c:compPick>
</aura:application>
=====================================================================================
=======
<aura:component >
<aura:if isTrue="{!v.edit}">
<ui:button label="Edit"/>
<aura:set attribute="else">
No button
</aura:set>
</aura:if>
</aura:component>
Application :
<aura:application>
<c:comp8></c:comp8>
</aura:application>
51
7 .LightningApexcall
_____________________________________________________________________________________
1. Every method of the apex which we want to invoke in the lightning should obey the following
rules
2. If you want to the apex class in the lightning component / application it should be define as a
controller
3.When we want to invoke the reffer to the server-side controller method from the client side
controller
method
Syntax :
component.get("c.methodName");
var mycall=component.get("c.methodName");
myCall.setcallback(this, function(response) {
logic
});
var state=response.getStatus();
52
6.Every apex method invocation from the controller javascript is asynchronous so we need to
$A.enqueueAction(action);
Example :
@AuraEnabled
<aura:component controller="AuraExample1">
</aura:component>
({
show : function(component) {
var action=component.get("c.getName");
action.setCallback(this, function(response){
53
if (state === "SUCCESS") {
component.set("v.empName",
response.getReturnValue());
});
$A.enqueueAction(action);
})
4. create a application
<aura:application >
<c:apexcall />
</aura:application>
=====================================================================================
==========
Example ; Reading a list account records from Sobject and display in Lightning
@AuraEnabled
return accs;
54
}
Component : Custom5 :
<aura:component controller="AuraExample2">
<p>{!a.Name} : {!a.Id}</p>
</aura:iteration>
</aura:component>
Controller:
({
getAccs: function(cmp){
action.setCallback(this, function(response){
cmp.set("v.Accounts", response.getReturnValue());
});
$A.enqueueAction(action);
})
55
Application :
<aura:application >
<c:custom5></c:custom5>
</aura:application>
8. Lightning ApexWithHTML
@AuraEnabled
return [SELECT id, Name, AccountNumber, Fax,Industry,Type FROM Account LIMIT 10];
========================
AccountListController
<thead>
<tr>
<th>Account Name</th>
<th>Account Number</th>
<th>Fax</th>
<th>Industry</th>
<th>Type</th>
</tr>
</thead>
56
<tbody>
<tr>
<td>{!account.Name}</td>
<td>{!account.AccountNumber}</td>
<td>{!account.Fax}</td>
<td>{!account.Industry}</td>
<td>{!account.Type}</td>
</tr>
</aura:iteration>
</tbody>
</table>
</div>
</aura:component>
=========================
({
action.setCallback(this, function(a) {
component.set("v.accounts", a.getReturnValue());
});
$A.enqueueAction(action);
})
================================
<aura:application >
57
<div class="container">
<div class="navbar-header">
</div>
<li><a href="#">Profile</a></li>
<li><a href="#">Messages</a></li>
</ul>
</div>
</nav>
</div>
<div class="container">
<div class="row">
<div class="col-sm-12">
<c:accountListComponent/>
</div>
</div>
</div>
</aura:application>
=========================
______________________________________________________________________________
Aura_Methods.txt
______________________________________________________________________________
<aura:component>
58
<aura:method name="defaultParamers" action="{!c.loadDefaultParams}">
</aura:method>
</aura:component>
==> Controller :
({
component.defaultParamers();
},
console.log(params);
if (params) {
})
=====================================================================================
@AuraEnabled
return new List<String>{'Salesforce header from Server' ,'Salesforce footer from Server' , 'Salesforce
title from Server' };
59
}
<aura:component controller="AuraMethodController">
</aura:method>
</aura:component>
Controller :
({
component.defaultParamers();
},
console.log(result);
if (params) {
onSucess;
action.setCallback(this, function(response) {
60
if (state === "SUCCESS") {
onSucess(response.getReturnValue());
});
$A.enqueueAction(action);
},
})
===========================================================================
Parent :
<aura:component >
</aura:method>
</aura:component>
({
component.defaultParamers();
},
if (params) {
61
var footer = params.footer;
console.log('title'+title)
},
})
Child:
<aura:component >
</aura:component>
({
},
})
===========================================================================
62
<aura:attribute type="String" name="header" default="Salesforce Header" />
</aura:method>
</aura:interface>
<aura:component implements="c:AuraMethodIntf">
</aura:component>
Controller:
({
component.defaultParamers();
},
if (params) {
console.log('title'+title);
console.log('header'+header);
console.log('footer'+footer);
},
63
})
_____________________________________________________________________________________
Design notes
<aura:component
implements="flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId"
access="global" >
</p>
</div>
</aura:component>
<design:component >
64
<design:attribute name="boxPadding" label="Padding" description="Enter Padding without 'px' [i.e
15]" />
<design:attribute name="textFontSize" label="Font Size" description="Enter font size without 'px' [i.e
15]" />
</design:component>
==============================================================
<aura:component
implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,
force:hasRecordId,forceCommunity:availableForAllPageTypes" access="global" >
<aura:attribute name = "Name" type = "String" ></aura:attribute> <!-- Define String Variable -->
<aura:attribute name = "Phone" type = "String" ></aura:attribute> <!-- Define Integer Variable -->
<aura:attribute name = "Position" type ="String" ></aura:attribute> <!-- Define Picklist Variable -->
<p>
Name: {!v.Name}
</p>
<p>
Number: {!v.Phone}
</p>
<p>
Position: {!v.Position}
</p>
</aura:component>
<design:component >
65
<design:attribute name ="Position" label="Position" datasource = "CEO, President,
Manager"></design:attribute>
</design:component>
=====================================================================================
============
<aura:component
implements="flexipage:availableForAllPageTypes,forceCommunity:availableForAllPageTypes"
access="global">
<div class="header-section-top">
{!v.welcomeTitle}
</div>
<aura:if isTrue="{!v.hideLogo}">
<div class="header-section-top">
</div>
</aura:if>
</div>
66
</aura:component>
<design:component>
</design:component>
___________________________________________________________________________________--
Interfaces
Interface :
==========
</aura:method>
</aura:interface>
component :
<aura:component implements="c:AuraMethodIntf">
67
</aura:component>
Client-Side :
({
component.defaultParamers();
},
if (params) {
console.log('title'+title);
console.log('header'+header);
console.log('footer'+footer);
},
})
_____________________________________________________________________________________
lightning:input
<lightning:input> :
2.This component supports HTML5 input types, including checkbox, date and datetime,
68
email, file, password, search, tel, url, number, radio, toggle.
SNO Type
1 Checkbox
2 Checkbox-button
3. color
4 Date
5. DateTime
6. Email
7. File
8. Month
9. Number
10. Password
11. Radio
11. Range
12. Search
13. Text
14. Time
15. Toggle
16. InputValidation
17. Week
Example :
1. CheckBox :
69
2. Checkbox-button
3. Color :
4. Date :
5. DateTime:
6. Email :
7. File :
8. Month :
9. Number
70
10. Password :
11. Radio :
12. Range :
13. Search :
14. Text :
15. Toogle :
16. Time :
Lightning_Pagination.txt
71
Pagination:
@AuraEnabled
@AuraEnabled
@AuraEnabled
@AuraEnabled
@AuraEnabled
@AuraEnabled
@AuraEnabled
72
//Total Records
cw.pageSize = pSize;
cw.pageNumber = pNumber;
cw.recordStart = offset + 1;
cw.totalRecords = totalRecords;
cw.contactList = [SELECT Id, Name, Phone, Email FROM Contact ORDER BY Name LIMIT :pSize
OFFSET :offset];
return cw;
<aura:component controller="ContactController">
<div class="slds-m-around_xx-large">
73
<h1 class="slds-text-heading--medium">Contacts</h1>
<br/>
<div class="slds-float_right">
</ui:inputSelect>
<br/>
</div>
<thead>
<tr class="slds-text-title_caps">
<th scope="col">
</th>
<th scope="col">
</th>
<th scope="col">
</th>
</tr>
</thead>
<tbody>
<tr>
74
<th scope="row" data-label="Name">
</th>
</th>
</th>
</tr>
</aura:iteration>
</tbody>
</table>
<div class="slds-clearfix">
<div class="slds-float_right">
</div>
</div>
</div>
</div>
</aura:component>
75
({
action.setParams({
"pageNumber": pageNumber,
"pageSize": pageSize
});
action.setCallback(this, function(result) {
component.set("v.ContactList", resultData.contactList);
component.set("v.PageNumber", resultData.pageNumber);
component.set("v.TotalRecords", resultData.totalRecords);
component.set("v.RecordStart", resultData.recordStart);
component.set("v.RecordEnd", resultData.recordEnd);
});
$A.enqueueAction(action);
})
({
76
},
pageNumber++;
},
pageNumber--;
},
var page = 1
},
})
6. Create a application ;
<aura:application extends="force:slds">
<c:Pagination_One />
</aura:application>
_____________________________________________________________________________________
Navigation
77
____________________________________________________________________________________
force:createRecord:
-------------------------------------------
Syntax:
var action=$A.get("e.force:createRecord");
action.setParams({"entityApiName":"ObjectName"});
Example :
---------
action.setParams({
"entityApiName": "Account"
});
action.fire();
----------------------------------------------------
force:editRecord
----------------------------------------------------
Syntax:
Example:
--------
action.setParams({
"recordId": recordId
78
});
action.fire();
----------------------------------------------------
force:navigateToList
-----------------------------------------------------
Syntax :
action.setParams({
"listViewId" : listViewId ,
"listViewName":name of listview,
"scope" : objectName
});
Example :
action.setParams({
"listViewId" : listviews.Id,
"listViewName": null,
"scope": "Contact";
});
action.fire();
--------------------------------------------------------
force:navigateToObjectHome
---------------------------------------------------------
79
Syntax :
Example :
----------
action.setParams({
"scope": "Account"
});
action.fire();
------------------------------------------------------
force:navigateToRelatedList
------------------------------------------------------
Syntax :
action.setParams({
});
Example :
----------
80
action.setParams({
"relatedListId": "Cases",
});
action.fire();
------------------------------------------------------
force:navigateToSObject
-------------------------------------------------------
Syntax :
action.setParams({
"slideDevName": "related"
});
Example :
----------
action.setParams({
"recordId":Id of record ,
"slideDevName": "related"
});
action.fire();
---------------------------------------------------
81
force:navigateToURL
--------------------------------------------------
Syntax :
action.setParams({
});
Example :
---------
action.setParams({
"url": "/006/o"
});
urlEvent.fire();
_____________________________________________________________________________________
Render Document
82
Rendering Lifecycles
Rendering and Rerendering lifecycles contains four basic methods to
render the component. These methods are :
1).render()
2).rerender()
3).afterRender()
4). unrender()
Custom Rendere
By overriding four basic methods of renderer we can update the DOM
elements.Let’s learn how.
1).render():
It returns DOM node, an array of DOM node or nothing. To override
the default rendering process we need to extend default render by
calling superRender() method then write custom code.Example:
83
render : function(component, helper) {
var returnVal = this.superRender();
// Write your custom code here.
return returnVal;
}
2).rerender():
It allows the component to update themselves, when other component
updates since they were last rendered. It doesn’t return any value. It
automatically called when data is updated in the component. Call
superRerender() to chain rerendering to the components in body
attribute.
Example:
3).afterRender():
It allows you to interact with DOM tree after rendering the DOM
elements. It doesn’t return a value. Call superAfterRender() before
your custom code to extend the default afterRender().
Example:
4). unrender():
84
It deletes all DOM nodes rendered by component’s render function. It
call by framework when components is being destroyed.
Example:
Render
The framework calls render() function when component is being initialized/rendered. The
render() function typically returns a DOM node, an array of DOM nodes, or nothing. The base
HTML component expects DOM nodes when it renders a component. Use render function to
modify DOM or to modify component markup.
1 //Component1.cmp
2 <aura:component>
10 },
11 })
12
13 //Component1Renderer.js
({
14
render: function(cmp, helper) {
15
console.log('render');
85
16
17 helper.changeValue(cmp);
18 return this.superRender()
19 },
20 })
21
In render() function I am calling helper method to modify DOM when component renders.
AfterRender
The afterRender function will be called by framework after render() function.AfterRender
function allows us to further change an already rendered component. The afterRender() function
enables you to interact with the DOM tree after the framework’s rendering service has inserted
DOM elements.
Note :
1. Both the functions will be called only once, you can keep your business logic that needs to
run only once in these functions.
2. Both functions can be used to modify DOM or markup.
3. Don’t perform DML in render function. You can do in afterRender.
Rerender
Rerender function will be called when a component’s value changes due to user action like a
button click or some other event like component/application event. Rerender function updates
component upon rerendering of the component.
1 //Component1.cmp
2 <aura:component>
86
11
12 </aura:component>
13
14 //Component1Controller.js
15 ({
component.set("v.truthy","false")
17
}
18
})
19
20
//Component1Renderer.js
21
({
22 rerender: function(cmp, helper) {
23 console.log('rerender');
24 return this.superRerender()
25 },
26 })
27
In above component when you click on “Check” button,update method will update component
which in turn call rerender.
Unrender
Framework fires an unrender event when a component is deleted.The base unrender() function
deletes all the DOM nodes rendered by a component’s render() function. It is called by the
framework when a component is being destroyed. Customize this behavior by overriding
unrender() in your component’s renderer. This can be useful when you are working with third-
party libraries that are not native to the framework.
1 //Component1.cmp
2 <aura:component>
3
<aura:attribute name="truthy" type="Boolean"></aura:attribute>
4
5
<aura:ifisTrue="{!v.truthy}">
6
87
7 <c:Component2 />
8 <aura:set attribute="else">
18 component.set("v.truthy","false")
19 }
})
20
21
//Component1Renderer.js
22
({
23
rerender: function(cmp, helper) {
24
console.log('rerender');
25 return this.superRerender()
26 },
27 })
28
29 //Component2.cmp
30 <aura:component>
88
35
36
unrender : function (cmp, helper) {
37
console.log('Component 2 unrender ');
38
return this.superUnrender();
39
},
40 })
41
42
Render:
========================================================================
Example 1:
<aura:component>
<div><b>{!v.msg}</b></div>
</aura:component>
89
({
changeValue : function(component) {
},
})
Render:
({
console.log('render');
helper.changeValue(cmp);
return this.superRender()
},
})
======================================
AfterRender
<aura:component>
<div><b>{!v.msg}</b></div>
</aura:component>
({
changeValue : function(component) {
},
90
})
Render:
({
console.log('render');
helper.changeValue(cmp);
return this.superAfterRender()
},
})
=======================================================================
ReRender :
=======================================================================
<aura:component>
<aura:if isTrue="{!v.truthy}">
True
<aura:set attribute="else">
False
</aura:set>
</aura:if>
</aura:component>
----------------------
({
91
component.set("v.truthy","false")
})
------------------------
({
console.log('rerender');
return this.superRerender()
},
})
========================================================================
UnRender :
<aura:component >
<aura:if isTrue="{!v.truthy}">
<c:Component2 />
<aura:set attribute="else">
</aura:set>
</aura:if>
</aura:component>
-------------------------------
({
92
component.set("v.truthy","false")
})
//Component1Renderer.js
({
console.log('rerender');
return this.superRerender()
},
})
---------------------
<aura:component >
I am in second component
</aura:component>
//Component2Renderer.js
({
return this.superUnrender();
},
})
=================================================================
Soap_Test_Class.txt
93
==> WSDL : Consumed :
name =ms.invoke('Satish','Myla');
Object stub,
Object request,
94
Map<String, Object> response,
String endpoint,
String soapAction,
String requestName,
String responseNS,
String responseName,
String responseType) {
response.put('response_x', name);
@isTest
@isTest
Test.setMock(WebserviceMock.class,res);
e.call();
System.assertEquals('Satish Myla',e.name);
=====================================================================================
======================
95
WSDL ==>Apex
acc.Name=res.name;
acc.Phone=res.phone;
acc.Email__c=res.email;
insert acc;
96
===>global class DummyResponse implements WebServiceMock {
Object stub,
Object request,
String endpoint,
String soapAction,
String requestName,
String responseNS,
String responseName,
String responseType) {
res.name='sam';
res.phone='040-1234';
res.email='[email protected]';
response.put('response_x', res);
@isTest
@isTest
Test.setMock(WebserviceMock.class,res);
e.callMe();
97
Account acc =[select Name,Phone,Email__C from Account];
System.assertEquals('Sam',acc.Name);
System.assertEquals('040-1234',acc.Phone);
System.assertEqauals('[email protected]',acc.Email__c);
Spinner
Class :
@AuraEnabled
return message;
Application :
-------------
<div class="exampleHolder">
</div>
</aura:application>
controller
==========
98
({
helper.showSpinner(component);
action.setCallback(this,function(response){
helper.hideSpinner(component);
});
$A.enqueueAction(action);
})
helper:
========
({
$A.util.removeClass(spinner, "slds-hide");
},
$A.util.addClass(spinner, "slds-hide");
})
99
SVG-Notes
style="fill:lime;stroke:purple;stroke-width:5;fill-rule:nonzero;" />
</svg>
<aura:component implements="flexipage:availableForAllPageTypes">
<p>SVG Example</p>
</aura:component>
=======================================================================
<aura:component implements="flexipage:availableForAllPageTypes">
<strong>Sample Component</strong>
</aura:component>
</svg>
=========================================================================
<aura:component implements="flexipage:availableForAllPageTypes">
<strong>Sample Component</strong>
</aura:component>
<?xml version="1.0"?>
100
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg xmlns="http://www.w3.org/2000/svg"
width="400" height="400">
</svg>
===========================================================
Token notes
<aura:tokens>
</aura:tokens>
MyComponent.cmp
<aura:component >
<div class="myClass">
</div>
</aura:component>
101
.THIS.myClass {
font-family: token(divFont);
font-weight: token(divFontWeight);
background-color: token(divBackgroundColor);
color: t(divTextColor);
margin: t(divMargin);
================================================================
first.tokens
<aura:tokens>
</aura:tokens>
two.tokens
<aura:tokens extends="c:first">
</aura:tokens>
defaulttokens.token
<aura:tokens extends="c:TokenForColors">
102
</aura:tokens>
component
==========
<aura:component >
<div class="myClass">
</div>
</aura:component>
.THIS.myClass {
_____________________________________________________________________________________
Interview Questions
103
Answer: It is the new user Interface developed by salesforce team, which is built on component-based
framework and event driven architecture, which provides a dynamic and responsive Experience to the
user. This framework is built to provide optimum performance by using stateful Client side and stateless
Server architecture.
1. Lightning Experience
2. Salesforce1 App
3. Template-based Community
There are many advantages of using lightning like it’s 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.
Yes. Lightning component works with Visualforce by implementing Lightning out as discussed earlier.
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.
Lightning App Builder – It is a tool with User interface to use drag and drop functionality and create app
fast by reusing the components, components can be standard or custom depending upon your
requirement.
104
Lightning Component Framework- it provides a bundle that can be used to build reusable custom
components, Standalone App and to customize Salesforce1 App
Lightning Connect – it is a powerful tool to facilitate the integration of force.com app with an external
data source using OData specification
Lightning Process Builder – it is a visualization tool to build automation required for your business
processes.
Lightning Schema Builder – it is a visualizing tool to view, create objects fields and relationship among
them.
No. Lightning component is not replacing Visualforce, Visualforce is still supported by Salesforce.
A Lightning component can be embedded in any webpage using a very powerful and flexible feature,
Lighting out. When used with Visualforce some complexity becomes simpler.
1. We have to first Add the Lightning Components for Visualforce JavaScript library to your targeted
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()
10. What are the type of events into Salesforce Lightning component?
Application Event – Scope of this event is throughout the lightning App and any component which has
registered for this event would get a notification.
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.
105
System Event- these are the events fired by Salesforce’s system during the lifecycle of the lightning app.
11. 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.
It is best to always use a component event instead of an application event. Component events can only
be handled by components above them in the containment hierarchy, therefore, their usage is localized
to the components that need to know about them.
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.
13. Can we integrate Lightning components with another framework, such as Angular?
To subscribe to an event in lightning component we need to include tag in the containment hierarchy.
Subscription of these event depends on the event type i.e. component event or application event. For
Component event we write below code.
In this ‘name’ attribute in should be exactly as name attribute in tag in the component which has fired
the component. The ‘action’ attribute of sets the client-side controller action to handle the event. The
‘event’ attribute specifies the event being handled.
‘Event’ and ‘action’ attributes are same as the component event handling, it is just that we do not
include ‘name’ attribute to handle the application event.
106
The Salesforce Lightning Design System (SLDS) component library is actively developed to enable
Salesforce developers to create a uniform look and feel across all Salesforce-related applications while
adhering to CSS best practices and conventions.
They are similar to a standard controller in Apex coding, advantages of using lightning Data service are
mentioned below
1. Use Lightning Data Service to load, create, edit, or delete a record in your component without
requiring Apex code.
2. Lightning Data Service handles sharing rules and field-level security for you.
3. In addition to not needing Apex, Lightning Data Service improves performance and user interface
consistency.
Lightning Connect
Aura is an open-source UI framework built by Salesforce for developing dynamic web apps for mobile
and desktop devices. Salesforce uses Aura to build apps, such as Lightning Experience and Salesforce1.
107
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.
documentation: A description, sample code, and one or multiple references to example components
SVG: Custom icon resource for components used in the Lightning App Builder or Community Builder.
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.
Component event: Component event is used to communicate with parent component using bubble
event.
Application event: Application events: to broadcast to other components and not exclusively ancestors.
Applications events can talk to many components that can be interested by the event.
108
implement is used to implement multiple interface in lightning component. e.g.
flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId
Lightning component can communicate using event communication framework. Read more about
component communication patterns.
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.
You can have namespace in your org but it is not necessary to have a namespace to develop lightning
component.
30. 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.
31. Which interface we are supposed to implement so that a lightning component can be used as quick
action?
109
We need to implement the following “force: lightningQuickAction” so that we can use the component as
a Quick Action
32. Which interface we are supposed to implement so that a lightning component can be used as a Tab?
We need to implement the following “force:appHostable” so that we can use the component as a Tab.
33. How can we call child component controller method from the parent component controller method?
To call a child component’s controller method, we need to first create a aura:method which is publically
accessible, aura:method is used to communicate down the containment hierarchy i.e. parent to child.
Sample code for implementing the aura method:
Component code
Controller
({
if (params) {
console.log(“message: ” + message);
return message;
})
({
var Result =
console.log(“Result: ” + Result);
110
})
a. Component
b. Controller
c. Helper
d. Style
e. Document
f. Design
g. SVG
h. Rendrer
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.
36. 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.
37. Can we make a Lightning Component that shows up in both the mobile and the desktop user
interfaces?
Lightning component is lightning experience ready by default and is also compatible in Salesforce1 App,
it has a responsive layout therefore it adjusts its resolution according the screen size and therefore can
be used on desktop as well without writing any separate code.
38. 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.
39. Can we make one component inherit styles/CSS from a parent component, or must we always define
it in the component?
111
Child component inherits the CSS from its aren’t we do not need to specify it for each component.
aura:method is used to communicate down the containment hierarchy i.e. parent to child.
42. Is there any limit on how many component to have in one Application?
43. 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.
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.
46. Do I always create an app bundle first when develop lightning component?
No, it is not necessary to create an App Bundle first to develop the lightning component.
Lightning component can be deployed to the production via change sets, force.com IDE, Managed
Package.
To make a component extendable we need to set value of ‘extensible’ attribute as ‘true’ of the
aura:component tag.
When a component extends another component it inherits all of the helper methods and attributes
49. How to register, fire and handle a component and application event?
112
We fire event as shown below:
compEvent.fire();
50. 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.
113
It adds the server-side controller action to the queue of actions to be executed. Rather than sending a
separate request for each individual action, the framework processes the event chain and batches the
actions in the queue into one request. The actions are asynchronous and have callbacks.
This adds namespacing to CSS and helps prevent one component’s CSS from blowing away another
component’s styling.
54. What are the different ways to conditionally display markup, and what is the preferred approach?
Use CSS to toggle visibility of markup by calling $A.util.toggleClass(cmp, ‘class’) in JavaScript code.
55. What is $Resource global value provider? Is it possible to obtain a reference to a static resource in
Javascript code?
It lets you reference images, style sheets, and JavaScript code you’ve uploaded in static resources.
56. 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?
Use event.getSource() in the client-side controller to get the button component that was clicked. Call
57. 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?
Add the force:hasRecordId interface to a Lightning component to enable the component to be assigned
the ID of the current record.
114
The recordId attribute is set only when you place or invoke the component in a context of a record. For
example, when you place the component on a record page, or invoke it as an action from a record page
or object home. In all other cases, such as when you create this component programmatically inside
another component, recordId isn’t set, and your component shouldn’t depend on it.
The Salesforce Lightning Design System (SLDS) component library is actively developed to enable
Salesforce developers to create a uniform look and feel across all Salesforce-related applications while
adhering to CSS best practices and conventions.
The framework enables you to control access to your applications, attributes, components, events,
interfaces, and methods via the access system attribute. The access system attribute indicates whether
the resource can be used outside of its own namespace.
You can specify these values for the access system attribute.
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.
61. 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.
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
115
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.
Lightning pages are referred as FlexiPages in API and referred as Lightning pages elsewhere in SFDC
documentation
Value providers helps use to access data in Lightning Application.They are two value providers as
v(View) and c(controller)
v is component attribute set which helps to access component attribute values in markup
c is component controller helps us to link with event handlers and action for the component
$globalID
$Browser
$Label
$Locale
$Resource
1. What is a component
2. What is a helper
116
3..What is a event
a. to create a tab
b. to override a button
8. what is recordid
10. recordViewForm
12. recordEditForm
16. $A.enqueueAction
18. @AuraEnabled
117
118