我需要将Apex页面转换为Lightning组件的帮助

时间:2019-07-01 16:02:00

标签: javascript salesforce apex salesforce-lightning

我对Apex和Salesforce都是全新的,并且正在尝试将Salesforce Page转换为Lightning组件。我提供了原始代码,并在下面提供了参考。我相信我缺少获取当前Case的AccountID的功能。我可能还很遥远,但我在这里寻求帮助和学习。 该组件应在表中列出父帐户的所有子域(URL)。下图显示了应完成的工作。 现在,该组件确实可以显示,并且在调试器中没有任何问题或错误,但是现在正在显示子域。甚至没有表标签“域名”。 Children Domains

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 ];
    }
}

0 个答案:

没有答案