+ Start a Discussion
Mee SharmaMee Sharma 

e.force:editRecord is not redirecting to edit page

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;
                  }

}
  
    
})

 
Mee SharmaMee Sharma
Here.. aura:iteration items="{!v.expense}" var="e">
sfdcMonkey.comsfdcMonkey.com
No i means where you have add this lightning component to check ? in record detail page beacuse This event is handled by the one.app container. It’s supported in Lightning Experience, the Salesforce app, and Lightning communities.
 
Mee SharmaMee Sharma
For now i have just created a custom lightning tab that displays expense records based on filters
Mee SharmaMee Sharma
I am checking in lightning experience. Added it as a tab. But the edit page is not displayed
sfdcMonkey.comsfdcMonkey.com
then we have need to debug this issue, contact with me on sfdcmonkey@gmail.com
Thanks
Manmohan Kaur 6Manmohan Kaur 6
I am getting the same error in my lightning component.