I want to redirect from child object (Primary_Terms__c) to parent record detail object(Acquisition_Deal) page using lightining component code

my apex class:

public class  acquisitiondeallightningcntrl 

public static list<Primary_Terms__c> getdealid(){

    return[SELECT Id,Acquisition_Deal__c FROM Primary_Terms__c];

Lightining component:

<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" controller="acquisitiondeallightningcntrl">
<aura:attribute name="deal" type="Acquisition_Deal__c[]"/>

   <aura:registerEvent name="navEvt" type="force:navigateToSObject"/>
     <aura:handler event="force:navigateToSObject" action="{!c.navigate}"/>

            <aura:handler name="init" action="{!c.doInit}" value="{!this}"/>
               <table class="slds-p-around_x-small slds-text-body_small slds-table slds-table--bordered slds-table--fixed-layout " >
                        <aura:iteration items="{!v.deal}" var="e">
                        <tr class="slds-hint-parent" >
                        <td><lightning:button variant="brand" label="Acquisition Deal" onclick="{!c.navigate}" />                       
                        <td scope="row">
                            <div class="slds-truncate slds-text-align--right" >
                            <a target="_blank" href="{!'/'+e.Id}">{!e.Name}</a>                                 


    doInit: function(component, event, helper) {

var action = component.get("c.getdealid");

action.setCallback(this, function(response) {
    var state = response.getState();
    if (component.isValid() && state === "SUCCESS") {
        component.set("v.deal", response.getReturnValue());
    else {
        console.log("Failed with state: " + state);

// Send action off to be executed


var idx= event.currentTarget.id;
var navEvt = $A.get("e.force:navigateToSObject");
"recordId": idx,
"slideDevName": "detail"



I am Getting Error:

Uncaught Action failed: c:Redirectingthepage$controller$navigate [Cannot read property 'current Target' of undefined]

please anyone help me to resolve this error and also for redirecting the parent page

  • try like this: var test = event.currentTarget;...Let me know still you are facing that error – Annappa PH Mar 26 '18 at 8:33
  • only event.currentTarget? @AnnappaPH – SFDC developer Mar 26 '18 at 8:35

You are getting error here.

var idx= event.currentTarget.id;

You are trying to access Id here from the current record. You can't access Id using this way. Also you didn't define event as parameter so you are getting error

Cannot read property 'current Target' of undefined

You can get Id: First pass Id in class attribute of button

<lightning:button variant="brand" label="Acquisition Deal" class="{!e.Id}" onclick="{!c.navigate}" />

and then in Controller

navigate: function(component,event){

This will give you Id which you can use in your code.

| improve this answer | |
  • @SFDCdeveloper Check in method parameter I have added event. Second I didn't use currentTarget so you might getting this error in some where else. – Tushar Sharma Mar 26 '18 at 8:41
  • Thank you,Now Page doesn't exist error is coming @Tushar sharma – SFDC developer Mar 26 '18 at 8:43
  • where i am doing mistake?@Tushar Sharma – SFDC developer Mar 26 '18 at 8:46
  • @SFDCdeveloper Try to print the Id in log and access that in browser. – Tushar Sharma Mar 26 '18 at 8:47
  • @SFDCdeveloper If you have followed my code you are printing the Id console.log(event.getSource().get("v.class")); here. Just try to access this Id in browser. – Tushar Sharma Mar 26 '18 at 8:50

Try like this,

I think you missed "event" in your method, that may causes error

   var test = event.currentTarget.id;
| improve this answer | |
  • Now Page doesn't exist error is coming @Annappa PH – SFDC developer Mar 26 '18 at 8:42
  • where i am doing mistake? @Annappa PH – SFDC developer Mar 26 '18 at 8:45
  • have you tried my code.? – Annappa PH Mar 26 '18 at 9:03
  • yes ,but Page doesn't exist error is coming @Annappa PH – SFDC developer Mar 26 '18 at 9:06
  • now you are raising different question..please post new question for that...thanks – Annappa PH Mar 26 '18 at 9:11

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.