0

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 

  {    
@AuraEnabled
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 " >
                   <thead>
                      </thead> 
                    <tbody>
                        <aura:iteration items="{!v.deal}" var="e">
                        <tr class="slds-hint-parent" >
                        <td><lightning:button variant="brand" label="Acquisition Deal" onclick="{!c.navigate}" />                       
                        </td>
                        <td scope="row">
                            <div class="slds-truncate slds-text-align--right" >
                            <a target="_blank" href="{!'/'+e.Id}">{!e.Name}</a>                                 
                            </div>
                            </td>
                           </tr>            
                         </aura:iteration>
                    </tbody>
                </table>
</aura:component>

Controller:

({
    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
$A.enqueueAction(action);
},

navigate:function(component,event,helper){
 console.log(event.getSource().get("v.class"));
var idx= event.currentTarget;
var navEvt = $A.get("e.force:navigateToSObject");
navEvt.setParams({
"recordId": idx,
"slideDevName": "detail"

 });
  navEvt.fire(); 
}   

 })

While Clicking Button,Page Does Not Exist error coming while redirecting the page,page does not exist error coming

  • 2
    @SFDC developer, please stop following up with questions in the comments, it is coutnerproductive. Instead, update your post, or create a new one iwth a new question. Thanks – glls Mar 26 '18 at 16:27
0

The button that you have created has no reference to the object you are trying to create the link to. I would use the name attribute of the lightning:button to store the Id as this value is optional and can be used to identify the button in a callback of the record I used the deal record Id as an example but the id you want to link to just bang it in there:

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

Then in the controller:

var idx = event.getSource().get('v.name');

Using event.currentTarget would return nothing useful in this case.

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.