function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
suri03081988suri03081988 

AURA Lightening Component : Record ID from VF page is not available in <aura:handler JS controller method

Hi All,

We are invoking the AURA component in VF page. We are passing record id from VF page to AURA component. 
The issue is, this record id is not avaiable in JS controller init method. It showing as undefined 

Code sample:

VF Page Code Sample:
<apex:page sidebar="false" showHeader="false" standardStylesheets="false">       
    <!-- Lightening Component code version starts -->
        <apex:includeLightning />
        <div  id="LightningCompContainer" />   
    <script>
        $Lightning.use("c:SampleAURA_App", function() {
            $Lightning.createComponent("c:SampleAURA_Component", {
            },
            "LightningCompContainer",
            function(component) {
               component.set("v.QuoteIDFromVfPage",'{!$CurrentPage.parameters.id}');
            });
        }); 
    </script>   
</apex:page>

AURA Lightening Component Code Sample:

<aura:component implements="force:appHostable" access="global" >    
    
    <!-- Handler - Init Method -->
    <aura:handler name="init" value="{!this}" action="{!c.initLoad}"/>
</aura:component>

JS Controller Code Sample:
({
    initLoad : function(component, event, helper) { 
        //Created var that store the recordIds of selected rows.
        var recordid = component.get("v.QuoteIDFromVfPage");
        alert('====>'+recordid);
     },
})

Final result is: Alert popup is showing "undefined"

One observation is:
This ID is not avoilable only in init method. The record ID is available in other JS controller methods which are triggerd from button.


Please help me on this issue

Thanks in advance,
Surendra
 
Best Answer chosen by suri03081988
mukesh guptamukesh gupta
Hi Suri,

Please use below code:-
 
<apex:page sidebar="false" showHeader="false" standardStylesheets="false">       
    <!-- Lightening Component code version starts -->
        <apex:includeLightning />
       <div id="lightning"/>   
    <script>

       $Lightning.use("c:SampleAURA_App", function() { 
           $Lightning.createComponent("c:SampleAURA_Component", 
             { "QuoteIDFromVfPage" :"      {!$CurrentPage.parameters.recordId}" }, 
             "lightning", 
               function(cmp) { 
                 console.log('Component Loaded'); 
                    }); 
              });
    </script>   
</apex:page>

if you need any assistanse, Please let me know!!

Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh

 

All Answers

suri03081988suri03081988
i missed the attribute "QuoteIDFromVfPage" in previous sample code, please refer this below code for AURA lightening component
<aura:component implements="force:appHostable" access="global" >    
    <aura:attribute name="QuoteIDFromVfPage" type="string" access="global"/>
    <!-- Handler - Init Method -->
    <aura:handler name="init" value="{!this}" action="{!c.initLoad}"/>
</aura:component>
mukesh guptamukesh gupta
Hi Suri,

Please use below code:-
 
<apex:page sidebar="false" showHeader="false" standardStylesheets="false">       
    <!-- Lightening Component code version starts -->
        <apex:includeLightning />
       <div id="lightning"/>   
    <script>

       $Lightning.use("c:SampleAURA_App", function() { 
           $Lightning.createComponent("c:SampleAURA_Component", 
             { "QuoteIDFromVfPage" :"      {!$CurrentPage.parameters.recordId}" }, 
             "lightning", 
               function(cmp) { 
                 console.log('Component Loaded'); 
                    }); 
              });
    </script>   
</apex:page>

if you need any assistanse, Please let me know!!

Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh

 
This was selected as the best answer
suri03081988suri03081988

Hi Mukesh,

its working, thank you so much for the help