Wednesday, September 5, 2018

Standard Object type attribute in Salesforce Lightning

Attribute can have a type corresponding to standard object.


<aura:attribute name="Accountobj" type="Account" 
description="Standard object type attribute"/>

Let's take an example of account object.

Step 1:Create Lightning Component.

<aura:component controller="Accountobjcontroller">  
//Apex controller:Accountobjcontroller

    <aura:attribute name="Accountobj" type="Account[]"/>  
//Standard object attribute


    <lightning:button label="Fetch Accounts" onclick="{!c.getaccount}"/>

    <aura:iteration var="acc" items="{!v.Accountobj}">

        <p>{!acc.Name} </p>



Step2:Create Javascript controller.


    getaccount: function(component){

        var action = component.get('c.getaccounts');
  //Calling controller method

        action.setCallback(this, function(response){

            var state = response.getState();

            if (state === "SUCCESS") {

                component.set("v.Accountobj", response.getReturnValue()); 
//Setting value in account object type attribute






Step 3: Create Apex controller.

public class Accountobjcontroller{

    public static List<Account> getaccounts() {

        List<Account> Acc =

                [SELECT Id, Name  FROM Account];

        return acc;
Step 4:Create Lightning Application

<aura:application extends="force:slds">

Component Attributes  in salesforce lightning

No comments:

Post a Comment