salesforce获取闪电组件中的帐户id



我已经开发了一个闪电组件模态弹出显示在机会页面。有"是"one_answers"否"两个选项。在这种情况下,这个闪电组件正在将流量传输到一个具有帐户id的visualforce页面或另一个页面。如何在闪电组件中获取帐户id。

<aura:component implements="force:lightningQuickActionWithoutHeader">
Are you sure you want to proceed?
<div class="slds-align_absolute-center">
<lightning:button
label="No"
variant="destructive"
onclick="{!handleNo}"
></lightning:button>
<lightning:button label="Yes" onclick="{!c.handleYes}"></lightning:button>
</div>
</aura:component>

,控制器为

({
handleNo: function (component, event, helper) {
var urlEvent = $A.get("e.force:navigateToURL");
urlEvent.setParams({
url: "/apex/MyOtherVisualforce",
isredirect: "true"
});
urlEvent.fire();
},
handleYes: function (component, event, helper) {
var urlEvent = $A.get("e.force:navigateToURL");
urlEvent.setParams({
url: "/apex/MyVisualforce",
isredirect: "true"
});
urlEvent.fire();
}
});

为了从机会中获得帐户Id,首先您需要获得正在执行快速行动的机会Id。这可以很容易地通过实现force:hasRecordId接口来实现(除了你已经实现的lightningQuickActionWithoutHeader接口)。通过这样做,您可以访问recordId属性,该属性在本例中已经包含机会的记录id (https://developer.salesforce.com/docs/component-library/bundle/force:hasRecordId/documentation)。

一旦您获得机会Id,您可以使用不同的方法获得相关帐户的Id。您可以创建一个Apex控制器,但您也可以使用force:recordData组件(https://developer.salesforce.com/docs/component-library/bundle/force:recordData/documentation)来获取帐户Id。

<aura:component implements="force:lightningQuickActionWithoutHeader,force:hasRecordId">
<aura:attribute type="Opportunity" name="opportunity" />
<force:recordData
recordId="{!v.recordId}"
fields="AccountId"
targetFields="{!v.opportunity}"
/>
Are you sure you want to proceed?
<div class="slds-align_absolute-center">
<lightning:button
label="No"
variant="destructive"
onclick="{!handleNo}"
></lightning:button>
<lightning:button label="Yes" onclick="{!c.handleYes}"></lightning:button>
</div>
</aura:component>

控制器:

({
handleNo: function (component, event, helper) {
var accountId = component.get("v.opportunity.AccountId");
var urlEvent = $A.get("e.force:navigateToURL");
urlEvent.setParams({
url: "/apex/MyOtherVisualforce",
isredirect: "true"
});
urlEvent.fire();
},
handleYes: function (component, event, helper) {
var accountId = component.get("v.opportunity.AccountId");
var urlEvent = $A.get("e.force:navigateToURL");
urlEvent.setParams({
url: "/apex/MyVisualforce",
isredirect: "true"
});
urlEvent.fire();
}
});

相关内容

  • 没有找到相关文章

最新更新