0% found this document useful (0 votes)
47 views2 pages

Lightning Apex Class

1. Apex classes used in Lightning components must have @AuraEnabled annotations on any methods or variables to be accessed. 2. Classes are defined as public with sharing and contain @AuraEnabled annotations. 3. Methods used in components must be public, static, and annotated with @AuraEnabled, and can return values and accept parameters.

Uploaded by

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

Lightning Apex Class

1. Apex classes used in Lightning components must have @AuraEnabled annotations on any methods or variables to be accessed. 2. Classes are defined as public with sharing and contain @AuraEnabled annotations. 3. Methods used in components must be public, static, and annotated with @AuraEnabled, and can return values and accept parameters.

Uploaded by

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

<apex:page >

Apex class :
-------------
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
b.Method should be public /global
c.Method should be static
d.Method can return any type of value
e.Method can have any type of parameters and any no of parameters
f. syntax :
@AuraEnabled
public static Integer callMe(){
return 10;
}

@AuraEnabled
public static Account callMe(String key){
return [select Name,Phone from Account where name:key limit
1];
}
<!--
@AuraEnabled
public static List<Account> callMe(String key){
return [select Name,Phone from Account where name:key ];
}

-->
4. if you want to invoke any variable directly in the component
a. variable should be public
b. varaible should have @Auraenabled
c. It can have any datatype
Example :
@AuraEnabled public String name {set;get;}
@AuraEnabled public Integer age {set;get;}

5. How to invoke the Apex class in lightning component


<!--
<aura:component controller="namespace:className" > : if we have
any custom namespace
<aura:component controller="ApexclassName" > : by default
it takes as "c"

-->

6. We can define only one apex class as controller in lightning component

7. If we want to define more than one apex class in the lightning component how
we define
Example 1:
public class Example extends Demo{
}
<!-- <aura:component controller="Example" > -->

Example 2;
<!--
one.cmp
<aura:component controller="Demo" >
</aura:component>

two.cmp
<aura:component extends="c:one" controller="Example">
</aura:component>
-->

8. How to invoke the apex class from client-side controller

Step 1:
var abc =component.get("c.apexMethodName");
a. This will invoke the method from the apex class and run the
operation
b. once the server-side operation is completed then it will call
callbackaction
Step 2: callback action
abc.setCallback(this,function(response){
logic
});
a. response : what ever the value returened by the apex class
this will stored as response
1. getState() : This will return the state of the action
a. SUCCESS
b. ERROR
c. NEW
4. INCOMPLETE
e. ABORTED
f. RUNNING

2. getReturnValue() :
a. if the apex class method has any return type ,value
returened by the method
will given by this

Step 3: Enqueue Action:

$A.enqueue(abc);

</apex:page>

You might also like