javascript - 我需要帮助将 Apex 页面转换为 Lightning 组件
问题描述
我是 Apex 和 Salesforce 的新手,我正在尝试将 Salesforce 页面转换为 Lightning 组件。我已经提供了原始代码,以及我在下面得到的参考。我相信我在获取当前案例的 AccountID 时遗漏了一些东西。我可能很遥远,但我在这里寻求帮助和学习。该组件应在表格中列出父帐户的所有子域(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 ];
}
}
解决方案
推荐阅读
- phpstorm - 如何使模板片段在blade.php 文件中可见?
- aws-lambda - Step Functions 忽略参数,使用默认输入执行它
- html - 表格列标题宽度不一样,表格主体和滚动条太大
- python - 由于来自 previos click 项目的表单发布方法,网页无法正确加载 - 当前页面显示未找到数据
- python - VSCode + Pylance:已识别类属性但没有可用的自动完成功能
- excel - 为什么 On Error Goto Label 第一次成功绕过错误后不起作用?
- java - java.text.ParseException:无法解析的日期。"dd MMM yyyy HH:mm:ss" 格式
- django - 注册时用户看不到 Django 中的消息错误
- excel - 优化 excel/google 表格中的销售问题
- python - Numpy.dot 给出相同的形状 (X, Y) (X,Y) 未对齐