0

I'm creating a button from a custom object's record, say for example 'OSample'. The button is to call a lightning component or form that enables the user to update a donation. since it needed to be available in classic also, i made this vf page to call the lightning component:

<apex:page sidebar="false" standardController="OSample__c">
<apex:includeLightning />    
<div id="donation" ></div>

<apex:includeScript value="{!$Resource.jquery_1_12_4}"/>
<apex:includeScript value="/soap/ajax/34.0/connection.js"/>
<apex:includeScript value="/soap/ajax/34.0/apex.js"/>

<script>
    var sampleId = "{!OSample__c.Id}";

    sforce.connection.sessionId = '{!$Api.Session_ID}';

    $Lightning.use("c:the_App", function(){
        $Lightning.createComponent("c:component1", {"comID" : sampleId }, "donation", function(component){});
     }); 
</script>

The passing of the ID value works on component1 but when I pass it again to another component, I didnt get the value anymore. I'm creating an event also for this.

<aura:event type="COMPONENT" description="Event template" >
<aura:attribute name="selectedPage" type="String"/>  
<aura:attribute name="samplerecord" type="Id"/> 
</aura:event>

This is component1:

<aura:component  access="global">
<aura:attribute name="selectedRecord" type="String" default="Step1"/>
<aura:attribute name="recordId" type="Id" />

<aura:if isTrue="{!v.selectedRecord== 'Step1'}">
    <c:component2 the_Id = "{!v.recordId}"/> //hoping i can pass the id to component2       
</aura:if> 

<aura:handler name="init" action="{!c.initializeRD}" value="{!this}" />
<aura:handler name="S_Event" event="c:SampleEvent" action="{!c.handleComponentEvent}"/>

Component2:

<aura:attribute name="the_Id" type="String"/>

....

but when I log the attribute value, it is undefined... how can I get the Id from the first component?

  • 1
    <aura:RegisterEvent> is missing...add it in your first component – cloudZigZag Jan 22 at 7:05
  • 1
    You are passing comID from the VF, whereas you are passing recordId from component1 to component2. How is recordId getting populated? – Jayant Das Jan 22 at 14:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.