【问题标题】:salesforce get account id in lightning componentSalesforce 在 Lightning 组件中获取帐户 ID
【发布时间】:2021-11-01 02:58:15
【问题描述】:

我开发了一个闪电组件模式弹出窗口以显示在机会页面上。有两个选项是和否。在此闪电组件将流传输到一个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();
  }
});

【问题讨论】:

    标签: components salesforce salesforce-lightning


    【解决方案1】:

    为了从商机中获取客户 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();
      }
    });
    

    【讨论】:

      猜你喜欢
      • 2018-12-11
      • 1970-01-01
      • 1970-01-01
      • 2019-09-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-15
      相关资源
      最近更新 更多