【问题标题】:Lightning Component, retrieving lookup record values in controllerLightning 组件,在控制器中检索查找记录值
【发布时间】:2019-05-17 16:56:55
【问题描述】:

我正在尝试将一个简单的 OnClick Javascript 按钮转换为 Lightning。这个 OnClick 非常简单,它只是打开一个 URL,但它使用父记录上的值作为 URL 的一部分。即,机会对象上的一个按钮,它将从其父帐户的 This_Field__c 字段中获取部分 URL:

    window.open('https://www.salesforce.com/'+'{!Account.This_Field__c}'+'/info');

所以如果字段上的值是 XYZ,这将打开页面https://www.salesforce.com/XYZ/info

在闪电组件中获取 Account.This_Field__c 值的最简单方法是什么?

考虑使用 Apex 控制器,但这似乎有点过头了。试过 force:recordData,似乎没有用,可能是因为它在父记录上。我们不希望 Opportunity 上有更多字段,否则我可能会尝试一个公式。

window.open('https://www.salesforce.com/'+'{!Account.This_Field__c}'+'/info');

如果字段上的值为 XYZ,这将打开页面https://www.salesforce.com/XYZ/info

【问题讨论】:

    标签: javascript salesforce field salesforce-lightning


    【解决方案1】:

    <force:recordData> 确实支持关系字段,尽管这一事实隐藏在文档中的 Lightning Data Service Considerations 页面中:

    Lightning Data Service 支持最大深度为五级的跨域。

    这是一个非常简单的例子:

    <aura:component implements="force:hasRecordId,flexipage:availableForRecordHome">
        <aura:attribute name="targetRecord" type="Object" />
    
        <force:recordData 
                          recordId="{! v.recordId }"
                          fields="Account.Website"
                          targetFields="{! v.targetRecord }"
                          />
    
        <aura:if isTrue="{! not(empty(v.targetRecord.Account.Website)) }">
            <a href="{! v.targetRecord.Account.Website }">Account Website</a>
        </aura:if>
    </aura:component>
    

    Apex 控制器也可以工作,但会增加复杂性,因为您必须编写 Apex、JavaScript 和 Apex 单元测试。

    最简单的解决方案是机会上的HYPERLINK() 公式。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-04-18
      • 2013-05-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-20
      • 1970-01-01
      相关资源
      最近更新 更多