Мне нужна помощь в преобразовании страницы Apex в компонент Lightning - PullRequest
1 голос
/ 01 июля 2019

Я новичок в Apex и Salesforce и пытаюсь преобразовать страницу Salesforce в компонент Lightning.Я предоставил исходный код, и где я попал ниже для справки.Я полагаю, что мне чего-то не хватает для получения идентификатора учетной записи текущего дела.Я могу быть далеко, но я здесь для помощи и для обучения.Компонент должен перечислить все дочерние домены (URL) родительской учетной записи в таблице.Ниже показано изображение того, какой должна быть законченная работа.Прямо сейчас компонент отображает, и в отладчике нет проблем или ошибок, но теперь отображаются дочерние домены.Даже табличный ярлык «Доменное имя». Детские домены

UPDATED CONTROLLER CLASS
public class CollectionCaseDomainsController {
    public List<Domain__c> domains {get;set;}

    @AuraEnabled
    public static void queryDomains(Domain__C domains, Id AccountId) {
        if (AccountId == null) { return; }

        //query all the children accounts (if any)
        Set<Id> allAccountIds = new Set<Id>{AccountId};
        Boolean done = false;
        Set<Id> currentLevel = new Set<Id>{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);
        }

        domains = [ 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="AccountId" type="Id" />
    <aura:attribute name="Domains" type="Domain__c" />
    <aura:attribute name="Columns" type="List" />

    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>

    <force:recordData aura:id="childDomains"
                      recordId="{!v.AccountId}"
                      targetFields="{!v.Domains}"
                      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>
LIGHTNING CONTROLLER
({
    doInit : function(component, event, helper) {
        component.set("v.Columns", [
            {label:"Domain Name", fieldName:"Domain__c", type:"url"}
        ]);

        var action = component.get("c.queryDomains");

        action.setParams({
            AccountId: component.get("v.AccountId")
        });

        action.setCallback(this, function(data) {
            component.set("v.Domains", data.getReturnValue());
        });

        $A.enqueueAction(action);
    }
})
ORIGINAL PAGE
<apex:page standardController="Case" extensions="CollectionCaseDomainsController"> 
    <apex:slds />

    <!-- Lightning -->
    <apex:outputPanel rendered="{! $User.UIThemeDisplayed == 'Theme4d' || $User.UIThemeDisplayed == 'Theme4t' }">
        <div class="slds-scope">
            <!-- Domains Found -->
            <apex:outputPanel rendered="{!NOT(ISNULL(domains)) && domains.size > 0}">
                <table role="grid" class="slds-table slds-table_fixed-layout slds-table_bordered slds-no-row-hover slds-scrollable_none">
                    <thead>
                        <tr class="slds-line-height_reset">
                            <th aria-label="Domain Name" aria-sort="none" class="slds-text-title_caps" scope="col">Domain Name</th>
                        </tr>
                    </thead>
                    <tbody>
                        <apex:repeat var="domain" value="{!domains}">
                            <tr class="slds-hint-parent">
                                <th scope="row">
                                    <a href="{!'/one/one.app?#/sObject/'+ domain.Id + '/view'}" target="_blank">{!domain.Name}</a>
                                </th>
                            </tr>
                        </apex:repeat>
                    </tbody>
                </table>
            </apex:outputPanel>
            <!-- No Domains -->
            <apex:outputLabel value="No records to display" rendered="{!(ISNULL(domains)) || domains.size == 0}" styleClass="noRowsHeader"></apex:outputLabel>
        </div>
    </apex:outputPanel>

    <!-- Classic -->
    <apex:form rendered="{! $User.UIThemeDisplayed == 'Theme3' }">                 
        <apex:pageblock id="DomainList"> 
            <br/> 
            <!-- Domains Found -->
            <apex:pageBlockTable value="{!domains}" var="domain" rendered="{!NOT(ISNULL(domains)) && domains.size > 0}">                
                <apex:column headerValue="Domain Name">
                    <apex:outputLink value="/{!domain.id}" target="_blank">{!domain.Name}</apex:outputLink>
                </apex:column>
            </apex:pageBlockTable>
            <!-- No Domains -->
            <apex:outputLabel value="No records to display" rendered="{!(ISNULL(domains)) || domains.size == 0}" styleClass="noRowsHeader"></apex:outputLabel> 
        </apex:pageblock> 
    </apex:form>
</apex:page>
ORIGINAL CONTROLLER
public class CollectionCaseDomainsController {
    public List<Domain__c> domains {get;set;}
    public Case current_case;

    public CollectionCaseDomainsController(ApexPages.StandardController stdController) {
        if (!Test.isRunningTest()) stdController.addFields(new List<String>{'AccountId'});
        this.current_case = (Case) stdController.getRecord();
        queryDomains();
    }

    public void queryDomains() {
        if (this.current_case.AccountId == null) { return; }

        //query all the children accounts (if any)
        Set<Id> allAccountIds = new Set<Id>{this.current_case.AccountId};
        Boolean done = false;
        Set<Id> currentLevel = new Set<Id>{this.current_case.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);
        }

        this.domains = [ SELECT Name FROM Domain__c WHERE Id IN :domainIds ];
    }
}
...