创建按钮,选择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:
-
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.
-
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.
-
Save the Visualforce page, ensure it is available for use.
-
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.
- 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.
本文详细描述了如何在Salesforce经典环境中通过创建Visualforce页面并嵌入代码来间接使用Lightning组件的过程,虽然非直接支持,但提供了一个工作示例和注意事项。
408

被折叠的 条评论
为什么被折叠?



