繁体   English   中英

salesforce 在 Lightning 组件中获取帐户 ID

[英]salesforce get account id in lightning component

我开发了一个闪电组件模态弹出窗口来显示在机会页面上。 有两个选项是和否。条件是此闪电组件将流传输到一个visualforce 页面或另一个具有帐户ID 的页面。 我如何在闪电组件中获取帐户 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 接口)。 通过这样做,您可以访问在这种情况下已经包含机会的记录 ID 的 recordId 属性 ( 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();
  }
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM