Thursday, 28 January 2021

Pass Record Id from Visualforce to Aura Lightning Component

This is the Visualforce Code for Pass the Record Id from the Visualforce page to Aura Component.

Let's Say we need to get and pass the Record Id from the below URL using only the Visualforce page to the Lightning Component.

https://dev-sfdc4students.cs74.force.com/?Id=a0A0p000001Z3F6

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<apex:page standardStylesheets="false" showHeader="false" >
    <!-- Include a JavaScript file in your Visualforce page -->
    
    <apex:includeLightning />
    <div id="lightning" />
    <script>
    
    //"cmpCustomerFeedbackApp" is your Lighning Component App Name (This is mandatory to create App)
    $Lightning.use("c:cmpCustomerFeedbackApp", function() {
        // "c:cmpCustomerFeedback" is your Lightning Component Name 
        // which is using in your Lightning Component App
        $Lightning.createComponent("c:cmpCustomerFeedback",
                                   {
                                       //"recordId" - This is your component attribute & is your Object Id
                                       "recordId" : "{!$CurrentPage.parameters.Id}",
                                   },
                                   "lightning",
                                   function(component) {
                                       // do some stuff
                                       //alert("{!$CurrentPage.parameters.Id}");
                                   });
    });
    </script>
</apex:page>

Thanks for your visit to my Blog. If this post is helpful to you then share and follow to get new coming SFDC4Students blog posts.

Total Pageviews