• Manmohan Kaur 6
  • NEWBIE
  • 0 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
Below is my lightning component that displays a table of expenses__c records based on a filter. I am trying to include an edit button for each row of the table so that when i click on it it redirects to the respective record edit page.

But i am getting the following error--"Action failed: c:Budgetdisplay$controller$edit [Cannot read property 'setParams' of undefined] Failing descriptor: {c:Budgetdisplay$controller$edit}"

Budgetdisplay.cmp
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes" access="global"  controller="budgetlightningcntrl" >
    <aura:attribute name="expense" type="Expenses__c[]"/>
    <aura:attribute name="allExpenses" type="Expenses__c[]" />
         
   <aura:handler event="c:statussearchkey" action="{!c.searchKeyChange}"/>
   <aura:handler name="init" action="{!c.doInit}" value="{!this}"/>

 <!-- PAGE HEADER -->
    
     <table >
               <!--Search component-->
                          
                      <tr>
                         <th scope="col" ><div class=" slds-text-align--left">Edit</div></th>
                        <th scope="col" ><div class=" slds-text-align--left">Expenses ID</div></th>
                        <th scope="col"><div class="slds-truncate  slds-text-align--right">Amount</div></th>
                        <th scope="col"><div class="slds-truncate  slds-text-align--right">Status</div></th>
                        <th scope="col"><div class="slds-truncate slds-text-align--right">My Budget</div></th>
                       </tr>
                    </thead> 
    
             <tbody>
                      <aura:iteration items="{!v.expense}" var="e">
                       <tr class="slds-hint-parent" >
                           <td> 
                               <lightning:button label="Edit Record" onclick="{!c.edit}"/>
    
                           </td>
                              <td scope="row">
                                <div class="slds-truncate slds-text-align--left" >
                                <a target="_blank" href="{!'/'+e.Id}">{!e.Name}</a>                                 
                                </div>
                                </td>
                            <td scope="row">
                            <div class="slds-truncate slds-text-align--right"><ui:outputNumber value="{!e.Amount__c}"/></div>
                            </td>
                            <td scope="row">
                            <div class="slds-truncate slds-text-align--right"><ui:outputText value="{!e.Status__c}" /></div>                            
                            </td>
                            <td>
                            <div class="slds-truncate slds-text-align--right">
                            <button type="button" onclick="{!c.navigate}" id="{!e.Budget__c}">check Budget</button> 
                            </div>
                          </td>
                     </tr>            
            </aura:iteration>
          </tbody>         
       </table>
    </aura:component>

Budgetdisplaycontroller.js
({
    doInit: function(component, event, helper) {

    // Create the action
    var action = component.get("c.getexpense");

    // Add callback behavior for when response is received
    action.setCallback(this, function(response) {
        var state = response.getState();
        if (component.isValid() && state === "SUCCESS") {
            component.set("v.expense", response.getReturnValue());
        }
        else {
            console.log("Failed with state: " + state);
        }
    });

    // Send action off to be executed
    $A.enqueueAction(action);
},
    
    searchKeyChange : function(component, event, helper){
    helper.findByName(component,event); 
}
  , 
     edit : function(component, event, helper) {
    var editRecordEvent  = $A.get("e.force:editRecord");
    editRecordEvent.setParams({

        "recordId" : component.get("v.expense.Id")

    });

    editRecordEvent .fire();

}
,
    navigate: function(component, event, helper) {
  var idx = event.currentTarget.id;
    var naviEvt = $A.get("e.force:navigateToSObject");
        if (naviEvt){
              naviEvt.setParams({
                 "recordId": idx ,
                 "slideDevName": "detail"
                });

                   naviEvt.fire();
                   }
                  else{
                      window.location.href = "/" + idx;
                  }

}
  
    
})