Skip to content

Instantly share code, notes, and snippets.

View saicharanreddyk's full-sized avatar

Saicharan Reddy K saicharanreddyk

View GitHub Profile
@saicharanreddyk
saicharanreddyk / How to take sObject as a return type into the component?
Created February 6, 2020 12:31
Lghtning - How to take sObject as a return type into the component?
In the below example we are passing sObject data i.e. acc the helper from there to controller fom there to component.
In the component when we initialized the attribute we didn't sepecify default as default="{'sObjectType':'Account'}"
because we are getting the acc data from Apex and we are sure that we are getting Account data only hence we didn't initialized.
<aura:handler name="init" value="{!this}" action="{!c.callMe}" /> -- Same as constructer. In this example we have only shown one record
if we want to display multiple records either we need to go for data table / iterator.
Component
************************************************************************************************************
<aura:component controller="Example_Four">
@saicharanreddyk
saicharanreddyk / Simple use case ( card, apex controller, layout, aura:if )
Created February 6, 2020 11:04
Lightning - Simple use case ( card, apex controller, layout, aura:if )
Component
**************************************************************
<aura:component controller="classWithParameters">
<aura:attribute name="name" type="String" />
<aura:attribute name="phone" type="String" />
<aura:attribute name="industry" type="String" />
<aura:attribute name="type" type="String" />
<aura:attribute name="result" type="String" />
<aura:attribute name="flag" type="Boolean" default="true"/>
<aura:attribute name="flag1" type="Boolean" default="false"/>
@saicharanreddyk
saicharanreddyk / How to invoke the apex class from client-side controller
Last active February 6, 2020 08:30
Lightning -- How to invoke the apex class from client-side controller
1. If you want to invoke any apex class in the in the lightning component
then the class should have @AuraEnabled methods or variables in it.
2. How to define a apex class
public with sharing class ClassName{
@AuraEnabled methods
@AuraEnabled variables
}
3. if you want to invoke any apex method in the lightning component then
a.Method should be annotated with @AuraEnabled
@saicharanreddyk
saicharanreddyk / Helper method
Created February 6, 2020 07:14
Lightning - Helper method
If there is any reusable code available then we will keep the code in helper and use it in controller
We can't directly call helper methods from component
Helper methods runs in different threads. Hence better performance
Component
*******************************************************************************************************
<aura:component >
<aura:attribute name="empName" type="String" />
<aura:attribute name="age" type="Integer" />
<aura:attribute name="salary" type="Decimal" />
@saicharanreddyk
saicharanreddyk / Display Array of elements or List or Set
Created February 6, 2020 05:58
Lightning - Display Array of elements or List or Set
To display Array of elements ot lists or set we can use iteration in lightning.
<aura:iteration items="{!v.student}" var="a">
items -- data on which we need to iterate
var -- The name of the variable to use for each item inside the iteration
aura:iteration iterates over a collection of items and renders the body of the tag for each item
Component
**********************************************************************************
<aura:component >
<aura:attribute name="student" type="List" default="['ABC','DEF','GHK','LMN','OPQ']" />
@saicharanreddyk
saicharanreddyk / Layout and LayoutItem
Last active February 6, 2020 05:25
Lightning - Layout and LayoutItem
A lightning:layout is a flexible grid system for arranging containers within a page or inside another container.
The default layout is mobile-first and can be easily configured to work on different devices.
A lightning:layoutItem is the basic element within lightning:layout.
You can arrange one or more layout items inside lightning:layout.
The attributes of lightning:layoutItem enable you to configure the size of the layout item,
and change how the layout is configured on different device sizes.
>> we need to use multipleRows="true" in order to get the benifit of lightning:layoutItem
>> default size is 12
@saicharanreddyk
saicharanreddyk / sObject Initialization
Created February 5, 2020 16:02
Lightning - sObject Initialization
When you are initializing sObject like below
<aura:attribute name="acc" type="Account" /> --> This is like Account acc; There is no memory allocation happened
hence while entering values we will get null issue.
"TypeError: d is null
throws at https://domain.lightning.force.com/auraFW/javascript/5fuxCiO1mNHGdvJphU5ELQ/aura_prod.js:544:409"
Correct way of initializing is
@saicharanreddyk
saicharanreddyk / aura:if
Created February 5, 2020 11:41
Lightning - Aura:if
aura:if evaluates the isTrue expression on the server and instantiates components in either its body or else attribute.
Only one branch is created and rendered. Switching condition unrenders and destroys the current branch and generates the other
<aura:if isTrue="{!v.truthy}">
If true process this piece of code
<aura:set attribute="else">
If false process this piece of code
</aura:set>
</aura:if>
@saicharanreddyk
saicharanreddyk / Read the values based on ids and set the values based on attributes
Created February 5, 2020 11:24
Lightning - Read the values based on ids and set the values based on attributes
I have got this strange doubt when we can read the values based on ids what is the use of <aura:attribute>
For displaying the data we can use output text. In this case we are reading and assigning the values in script i.e. controller.
In order to display values in markup i.e. component we need attributes
Component
************************************************************************************************
<aura:component >
<aura:attribute name="FirstName" type="String" />
<aura:attribute name="LastName" type="String" />
<aura:attribute name="DateOfBirth" type="Date" />
@saicharanreddyk
saicharanreddyk / How to identify which button was clicked using event
Created February 5, 2020 10:29
Lightning - How to identify which button was clicked using event
In order to find which button was clicked we can use event methods.
In the below example I used three button.
With below piece of code we can find which button was clicked. On click of a button a controller method will be called
inside that methos we can use event methods to capture the information.
var source = event.getSource(); // From which element/source event was fired ?
var id = evt.getLocalId(); // Id of the element from which event was fired
var name = evt.get("v.name"); // Name of the element from which event fired