У меня есть Lightning Accordion, содержащий таблицу данных, которая не получает данные объекта для заполнения таблицы. Компонент получает объект Case, сохраняя его как recordData, и отправляет его в мой класс контроллера.
Он должен отображать данные всех дочерних доменов родительской учетной записи, как показано ниже в примере.
введите описание изображения здесь
CONTROLLER CLASS:
public class CollectionCaseDomainsController {
@AuraEnabled
public static List<Domain__c> queryDomains(Case CurrentCase) {
// if (CurrentCase.AccountId == null) { return;}
//query all the children accounts (if any)
Set<Id> allAccountIds = new Set<Id>{CurrentCase.AccountId};
Boolean done = false;
Set<Id> currentLevel = new Set<Id>{CurrentCase.AccountId};
Integer count = 0;
while(!done) {
List<Account> children = [ SELECT Id FROM Account WHERE Parent.Id IN :currentLevel ];
count++;
currentLevel = new Set<Id>();
for (Account child : children) {
currentLevel.add(child.Id);
allAccountIds.add(child.Id);
}
//added in a count, to prevent this getting stuck in an infinate loop
if (currentLevel.size() == 0 || count > 9) {
done = true;
}
}
//query the assets
List<Asset> assets = [ SELECT Domain__c FROM Asset WHERE AccountId IN :allAccountIds ];
Set<Id> domainIds = new Set<Id>();
for (Asset a : assets) {
domainIds.add(a.Domain__c);
}
return [ SELECT Name FROM Domain__c WHERE Id IN :domainIds ];
}
}
LIGHTNING COMPONENT:
<aura:component controller="CollectionCaseDomainsController" implements="flexipage:availableForRecordHome,force:hasRecordId" access="global" >
<aura:attribute name="recordId" type="Id" />
<aura:attribute name="CurrentCase" type="Case" />
<aura:attribute name="Domains" type="List" />
<aura:attribute name="Columns" type="List" />
<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
<force:recordData aura:id="caseRecord"
recordId="{!v.recordId}"
targetFields="{!v.CurrentCase}"
layoutType="FULL"
/>
<lightning:accordion activeSectionName="Domains">
<lightning:accordionSection name="Domains" label="Domains">
<lightning:datatable data="{ !v.Domains }" columns="{ !v.Columns }" keyField="Id" hideCheckboxColumn="true"/>
</lightning:accordionSection>
</lightning:accordion>
</aura:component>
COMPONENT CONTROLLER:
({
doInit : function(component, event, helper) {
component.set("v.Columns", [
{label:"Domain Name", fieldName:"Name", type:"text"}
]);
var action = component.get("c.queryDomains");
action.setParams({
CurrentCase: component.get("v.CurrentCase")
});
action.setCallback(this, function(data) {
var state = data.getState();
if (state === "SUCCESS") {
component.set("v.Domains", data.getReturnValue());
} else {
console.log("Failed with state: " + state);
}
});
// Send action off to be executed
$A.enqueueAction(action);
}
})