You need to sign in to do that
Don't have an account?
David 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
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
Hope this helps others.
accountSummary.cmp
-----------------------------
<aura:component controller="accountSummaryController"
implements="force:lightningQuickActionWithoutHeader,force:hasRecordId,force:appHostable,flexipage:availableForAllPageTypes">
<!-- 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>
</div>
<!-- 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>
<div class="slds-form-element">
<p class="slds-text-heading--label">{!v.account.BillingState}</p>
</div>
<div class="slds-form-element">
<p class="slds-text-heading--label">{!v.account.Website}</p>
</div>
</div>
</aura:component>
accountSummaryController.js
---------------------------------------
({
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);
}
});
$A.enqueueAction(action);
}
})
...and the controller class
accountSummaryController.apxc
-------------------------------------------
public with sharing class accountSummaryController {
@AuraEnabled
public static Account getAccount(Id accountId) {
// Perform isAccessible() checks here
return [SELECT Name, BillingCity, BillingState,website FROM Account WHERE Id = :accountId];
}
}
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
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
Hope this helps others.
accountSummary.cmp
-----------------------------
<aura:component controller="accountSummaryController"
implements="force:lightningQuickActionWithoutHeader,force:hasRecordId,force:appHostable,flexipage:availableForAllPageTypes">
<!-- 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>
</div>
<!-- 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>
<div class="slds-form-element">
<p class="slds-text-heading--label">{!v.account.BillingState}</p>
</div>
<div class="slds-form-element">
<p class="slds-text-heading--label">{!v.account.Website}</p>
</div>
</div>
</aura:component>
accountSummaryController.js
---------------------------------------
({
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);
}
});
$A.enqueueAction(action);
}
})
...and the controller class
accountSummaryController.apxc
-------------------------------------------
public with sharing class accountSummaryController {
@AuraEnabled
public static Account getAccount(Id accountId) {
// Perform isAccessible() checks here
return [SELECT Name, BillingCity, BillingState,website FROM Account WHERE Id = :accountId];
}
}
What is the issue/error you are facing? Can you share the details?
-Thanks,
TK