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
sandhya santhanagopalansandhya santhanagopalan 

how to pass record id from one component to another

I have multiple components created which creates vendor details on multiple components, which gets updated on single object in backend. For this, i need to pass on the record id created in the first component to the other components.so that, info on multiple components save on save vendor record.
I have created an event.how to pass the record id created to event and theron passs to other components.
Thank you.
Best Answer chosen by sandhya santhanagopalan
NagendraNagendra (Salesforce Developers) 
Hi Sandhya,

I have been working on a similar issue in the recent past.

Please check with this which will point you in the right direction.

I have two lightning components:

first component:

<aura:component controller="ActionController"  implements="force:hasRecordId,force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:lightningQuickAction" access="global">
    <aura:attribute name="theId" type="String"/>
    <aura:attribute name="options" type="String[]"/>
    <aura:attribute name="wrplst" type="WrapperCriteria[]"/>
    <aura:attribute name="selectedValue" type="String"/>
    <aura:handler name="deleteJob" event="c:deleteJobEvt" action="{!c.RemoveClick}" />
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
    <p>
       <b>Creating Action Criteria </b>
    </p>
    <h3 class="slds-section-title--divider">
       <b>
           <I> Action Criteria</I>
       </b>
    </h3>
    <table >
        <tr class="slds-text-title--caps">
           <th class="head">
               <I>Action</I>
           </th>
           <th class="head">
               <I>Object Name</I>
           </th>
           <th class="head">
               <I>Component</I>
           </th>
           <th class="head">
               <I>Operator</I>
           </th>
           <th class="head">
               <I>Special Operator</I>
           </th>
           <th class="head">
               <I>Special Operator * Value</I>
           </th>
           <th class="head">
               <I>Special Operator / Value</I>
           </th>
     </tr>
     <aura:renderIf isTrue="{!v.wrplst.length > 0}">
        <c:NewAction options="{!v.options}" selectedValue="" />
        <aura:iteration items="{!v.wrplst}" var="a">
            <c:NewAction wrp="{!a}"/>
         </aura:iteration>
     </aura:renderIf>
</table>
<lightning:button variant="brand" label="Add row" onclick="{!c.AddRow}" />
<lightning:button variant="brand"  label="Save" onclick="{!c.saveRow}" />
NewAction :
<aura:component controller="ActionController" >
    <aura:attribute name="wrp" type="WrapperCriteria[]"/>
    <aura:attribute name="idval" type="String"/>
    <aura:attribute required="true" name="options" type="String[]"/>
    <aura:attribute required="true" name="selectedValue" type="String"/>
    <aura:attribute name="wpchange" type="List" />
    <aura:registerEvent name="deleteJob" type="c:deleteJobEvt"/>

    <tr>
        <td class="cell" style="padding-top:14px;padding-bottom:0px;">
           <p >
              <button type="button" onclick="{!c.RemoveClick}" >remove</button>
           </p>
       </td>
       <td class="cell" >
           <p>
               <lightning:select name="mySelect" label=" " value="{!v.selectedValue}" onchange="{!c.dosomething}">
                    <aura:iteration items="{!v.options}" var="item">
                        <option text="{!item.label}" value="{!item.value}" selected="{!item.selected}"/>
                    </aura:iteration>
               </lightning:select> 
           </p>
      </td>
      <td class="cell" >
           <lightning:select name="select" label=" " aura:id="o" >
                <option value="">None</option>
           </lightning:select>
       </td>
       <td class="cell" >
           <p>
               <lightning:select name="selectItem" label=" ">
                   <option value="None">None</option>
                   <option value="+ Addition">+ Addition</option>
                   <option value="- Subtract  ">- Subtract</option>
                   <option value="* Multiply ">* Multiply</option>
                   <option value="/ Divide">/ Divide</option>
               </lightning:select>
           </p>
      </td>
      <td class="cell" >
          <p>
              <lightning:select name="selectItem" label=" " >
                  <option value="None">None</option>
                  <option value="*">*</option>
                  <option value="*/">*/</option>
                  <option value="/">/</option>
              </lightning:select>
          </p>
      </td>
      <td class="cell"  style="padding-top:14px;padding-bottom:0px;">
          <p>
              <ui:inputText value="{!v.wrp.specialOperatorValue}"/>
          </p>
      </td>
      <td class="cell"  style="padding-top:14px;padding-bottom:0px;">
          <p>
              <ui:inputText value="{!v.wrp.specialOperatorSlashValue}"/>
          </p>
      </td>
  </tr>

For this, I have created an attribute:

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

use this to pass id to NewAction like below:

<c:NewAction options="{!v.options}" selectedValue="" idval="{!v.id}" />
Hope this will answer your question.

Kindly mark this as solved if it's resolved so that it gets removed from the unanswered queue which results in helping others who are encountering a similar issue.

Thanks,
Nagendra
 


 

All Answers

NagendraNagendra (Salesforce Developers) 
Hi Sandhya,

I have been working on a similar issue in the recent past.

Please check with this which will point you in the right direction.

I have two lightning components:

first component:

<aura:component controller="ActionController"  implements="force:hasRecordId,force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:lightningQuickAction" access="global">
    <aura:attribute name="theId" type="String"/>
    <aura:attribute name="options" type="String[]"/>
    <aura:attribute name="wrplst" type="WrapperCriteria[]"/>
    <aura:attribute name="selectedValue" type="String"/>
    <aura:handler name="deleteJob" event="c:deleteJobEvt" action="{!c.RemoveClick}" />
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
    <p>
       <b>Creating Action Criteria </b>
    </p>
    <h3 class="slds-section-title--divider">
       <b>
           <I> Action Criteria</I>
       </b>
    </h3>
    <table >
        <tr class="slds-text-title--caps">
           <th class="head">
               <I>Action</I>
           </th>
           <th class="head">
               <I>Object Name</I>
           </th>
           <th class="head">
               <I>Component</I>
           </th>
           <th class="head">
               <I>Operator</I>
           </th>
           <th class="head">
               <I>Special Operator</I>
           </th>
           <th class="head">
               <I>Special Operator * Value</I>
           </th>
           <th class="head">
               <I>Special Operator / Value</I>
           </th>
     </tr>
     <aura:renderIf isTrue="{!v.wrplst.length > 0}">
        <c:NewAction options="{!v.options}" selectedValue="" />
        <aura:iteration items="{!v.wrplst}" var="a">
            <c:NewAction wrp="{!a}"/>
         </aura:iteration>
     </aura:renderIf>
</table>
<lightning:button variant="brand" label="Add row" onclick="{!c.AddRow}" />
<lightning:button variant="brand"  label="Save" onclick="{!c.saveRow}" />
NewAction :
<aura:component controller="ActionController" >
    <aura:attribute name="wrp" type="WrapperCriteria[]"/>
    <aura:attribute name="idval" type="String"/>
    <aura:attribute required="true" name="options" type="String[]"/>
    <aura:attribute required="true" name="selectedValue" type="String"/>
    <aura:attribute name="wpchange" type="List" />
    <aura:registerEvent name="deleteJob" type="c:deleteJobEvt"/>

    <tr>
        <td class="cell" style="padding-top:14px;padding-bottom:0px;">
           <p >
              <button type="button" onclick="{!c.RemoveClick}" >remove</button>
           </p>
       </td>
       <td class="cell" >
           <p>
               <lightning:select name="mySelect" label=" " value="{!v.selectedValue}" onchange="{!c.dosomething}">
                    <aura:iteration items="{!v.options}" var="item">
                        <option text="{!item.label}" value="{!item.value}" selected="{!item.selected}"/>
                    </aura:iteration>
               </lightning:select> 
           </p>
      </td>
      <td class="cell" >
           <lightning:select name="select" label=" " aura:id="o" >
                <option value="">None</option>
           </lightning:select>
       </td>
       <td class="cell" >
           <p>
               <lightning:select name="selectItem" label=" ">
                   <option value="None">None</option>
                   <option value="+ Addition">+ Addition</option>
                   <option value="- Subtract  ">- Subtract</option>
                   <option value="* Multiply ">* Multiply</option>
                   <option value="/ Divide">/ Divide</option>
               </lightning:select>
           </p>
      </td>
      <td class="cell" >
          <p>
              <lightning:select name="selectItem" label=" " >
                  <option value="None">None</option>
                  <option value="*">*</option>
                  <option value="*/">*/</option>
                  <option value="/">/</option>
              </lightning:select>
          </p>
      </td>
      <td class="cell"  style="padding-top:14px;padding-bottom:0px;">
          <p>
              <ui:inputText value="{!v.wrp.specialOperatorValue}"/>
          </p>
      </td>
      <td class="cell"  style="padding-top:14px;padding-bottom:0px;">
          <p>
              <ui:inputText value="{!v.wrp.specialOperatorSlashValue}"/>
          </p>
      </td>
  </tr>

For this, I have created an attribute:

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

use this to pass id to NewAction like below:

<c:NewAction options="{!v.options}" selectedValue="" idval="{!v.id}" />
Hope this will answer your question.

Kindly mark this as solved if it's resolved so that it gets removed from the unanswered queue which results in helping others who are encountering a similar issue.

Thanks,
Nagendra
 


 

This was selected as the best answer
pradeep kumar yadavpradeep kumar yadav
For this, like this component:
 
<aura:attribute name="idval" type="String"/>



use this to pass id to NewAction like below:
 
<c:NewAction options="{!v.options}" selectedValue="" idval="{!v.id}" />

 
sandhya santhanagopalansandhya santhanagopalan
Thanks Nagendra and Pradeep.I have included force:hasRecordId in aura:component.So, on save of the component the record id has to be populated in v.recordid.But when i try to display console.log(component.get("v.recordId")) in my controller it shows an error "undefined".
Correct me if i m wrong.Thanks.
sandhya santhanagopalansandhya santhanagopalan
pl help yar.its urgent.
sandhya santhanagopalansandhya santhanagopalan
Can i use v.id from <c:NewAction options="{!v.options}" selectedValue="" idval="{!v.id}" /> in other components(newAction) controller directly?
sandhya santhanagopalansandhya santhanagopalan
i have used events for this.