+ Start a Discussion
David Roberts 4David Roberts 4 

very simple lightning component returning Account information.

I struggled to create a simple Lightning Component that I could add to an account page, so thought I'd share my result.
The presentation of the information isn't tidy yet...that's my next learning excercise!
This can also be used as an action via an action button on the page.
It was based on the article

Hope this helps others.

<aura:component controller="accountSummaryController"
    <!-- based on https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/components_using_lex_s1_config_action_recordid.htm#components_using_lex_s1_config_action_recordid -->

     <aura:attribute name="account" type="Account" />

    <aura:handler name="init" value="{!this}" action="{!c.doInit}" />
    <!-- Display details about the account -->
    <div class="slds-page-header" role="banner">
        <p class="slds-text-heading--label">{!v.account.Name}</p>
    <!-- Display the details form needs work -->
    <div class="slds-form--stacked">
    <div class="slds-form-element">       
        <p class="slds-text-heading--label">{!v.account.BillingCity}</p>
        <div class="slds-form-element">    
        <p class="slds-text-heading--label">{!v.account.BillingState}</p>
    <div class="slds-form-element"> 
        <p class="slds-text-heading--label">{!v.account.Website}</p>



    doInit : function(component, event, helper) {

        // Prepare the action to load account record
        var action = component.get("c.getAccount");
        action.setParams({"accountId": component.get("v.recordId")});

        // Configure response handler
        action.setCallback(this, function(response) {
            var state = response.getState();
            if(component.isValid() && state === "SUCCESS") {
                component.set("v.account", response.getReturnValue());
            } else {
                console.log('Problem getting account, response state: ' + state);

...and the controller class

public with sharing class accountSummaryController {

    public static Account getAccount(Id accountId) {
        // Perform isAccessible() checks here
        return [SELECT Name, BillingCity, BillingState,website FROM Account WHERE Id = :accountId];
Tarun Khatri (TK)Tarun Khatri (TK)
Hello David,

What is the issue/error you are facing? Can you share the details?

David Roberts 4David Roberts 4
Hi Tarun, Thank you for your quick reply but I don't have a problem. I did have (!) and it took days to solve. I couldn't find a solution so posted this for the next person who struggles. They, at least, will find help. Kind regards, Dave Roberts Business Development Manager +44 (0) 1908 448877 +44 (0)7908 652985 david.roberts@logicom.com www.virtualworlds.co.uk 1 Portland Drive, Willen, Milton Keynes, MK15 9JW, UK Stand out from the crowd...
Tarun Khatri (TK)Tarun Khatri (TK)
Good Job... :)