salesforce点击classic按钮调用lightning组件

本文详细描述了如何在Salesforce经典环境中通过创建Visualforce页面并嵌入代码来间接使用Lightning组件的过程,虽然非直接支持,但提供了一个工作示例和注意事项。

创建按钮,选择visualforce 页面,然后创建visualforce页面。

how to Call a Lightning component from a Classic custom button
You can definitely call a Lightning Component from a Classic custom button. However, the process is not straightforward as Lightning components are not meant to be directly used in Salesforce Classic, but workarounds could be made to make them usable.

Here’s a sample process of doing this:

  1. Create your Lightning Component. Please ensure that the component is globally accessible as we are going to use it outside the Lightning Environment. Also, ensure that you have added the component to a Lightning Application.

  2. Create a Visualforce Page to embed the line of code to include the Lightning component in the page. Here’s a sample code of how to do it:

<apex:page standardController="Account"> <!-- specify the object -->
  <apex:includeLightning />
  <div id="lightning" />

  <script>
    $Lightning.use("c:myLightningApp", function() {
      $Lightning.createComponent("c:myLightningComponent",
          { accountId : "{!Account.Id}" }, // pass record id to the component
          "lightning",
          function(cmp) {
            // do some extra stuff after component creation
          });
    });
  </script>
</apex:page>

*Note: c:myLightningApp refers to the Lightning Application that holds your component; and c:myLightningComponent refers to your Lightning Component.

  1. Save the Visualforce page, ensure it is available for use.

  2. Now, create a Classic custom button. In the button setup, choose ‘Display in new window’ as the behavior, and ‘URL’ as the content source, then in the URL field put in:

/apex/YourVisualforcePagename?Id={!Account.Id}

Replace “YourVisualforcePagename” with the actual API name of your visualforce page, and also replace “Account.Id” with the actual object id you are working with if not Account.

  1. After all these, save the button. You can add it to the layout of the object you are working with.

Please note this procedure works but is a workaround, Salesforce doesn’t support directly using Lightning Components in Salesforce Classic.

Also, make sure to test all scenarios before deploying it to production.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值