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
Mạnh NguyễnMạnh Nguyễn 

Error : Cannot read property 'setParams' of undefined

i have a quest : 
- create a list view contact
- list have edit + view button

this is my code : 

listview.cmp
<aura:component controller="ContactController" implements="force:appHostable,
                                                           flexipage:availableForAllPageTypes,
                                                           force:hasRecordId">
    
    <aura:attribute type="Contact[]" name="contList"/>
    <aura:attribute name="mycolumns" type="List"/>
    
    <aura:handler name="init" value="{!this}" action="{!c.fetchCt}"/>
    
    <lightning:datatable data="{! v.contList }"
                         columns="{! v.mycolumns }"
                         keyField="id"
                         hideCheckboxColumn="true"
                         onrowaction="{!c.handleRowAction}" />"
</aura:component>

listviewController.js
({
    fetchCt : function(component, event, helper) {
        var actions = [
            {label:'Edit',name:'edit'},
            {label:'View',name:'view'}
        ];
        component.set('v.mycolumns', [
            {label: 'ContactName', fieldName: 'Name', type: 'text'},
            {label: 'Email', fieldName: 'Email', type: 'text'},
            {label: 'Phone', fieldName: 'Phone', type: 'Phone'},
            {label: 'Title', fieldName: 'Title', type: 'Text'},
            {label:'Status',fieldName:'Status',type:'picklist'},
            {type:'action',typeAttributes:{rowActions:actions}}
        ]);
        var action = component.get("c.fetchContacts");
        action.setCallback(this, function(response){
            var state = response.getState();
            if (state === "SUCCESS") {
                component.set("v.contList", response.getReturnValue());
            }
        });
        $A.enqueueAction(action);
    },
    handleRowAction: function ( cmp, event, helper ) {
        
        var action = event.getParam( 'action' );
        var row = event.getParam( 'row' );
        var recId = row.Id;
        console.log('RecordId',recId);
        switch ( action.name ) {
            case 'edit':
                var editRecordEvent = $A.get("e.force:editRecord");
                editRecordEvent.setParams({
                    "recordId": recId
                });
                editRecordEvent.fire();
                break;
            case 'view':
                var viewRecordEvent = $A.get("e.force:navigateToURL");
                viewRecordEvent.setParams({
                    "url": "/" + recId
                });
                viewRecordEvent.fire();
                break;
        }
    }
})

contactController.apxc
public class ContactController {
    @AuraEnabled
    public static List <Contact> fetchContacts() {
        //Qyery 10 accounts
        List<Contact> contList = [Select Id, Name, Email, Title, Phone From Contact];
        //return list of accounts
        return contList;
    }
}


i used this doc : 
https://developer.salesforce.com/docs/component-library/bundle/force:editRecord/documentation

Error : 
This page has an error. You might just need to refresh it. Action failed: c:listView$controller$handleRowAction [Cannot read property 'setParams' of undefined] Failing descriptor: {c:listView$controller$handleRowAction}
User-added image

please someone have me, thanks.
Best Answer chosen by Mạnh Nguyễn
Maharajan CMaharajan C
Hi Manh, 

I think you previewing the component through <aura:application extends="force:slds">.

then e.force:editRecord and e.force:navigateToURL will not work in Lightning Standalone App. 

You can drag this same component in lighnting Home page or Record Pages via app builder then it will work.

Thanks,
Maharajan.C

All Answers

Maharajan CMaharajan C
Hi Manh, 

I think you previewing the component through <aura:application extends="force:slds">.

then e.force:editRecord and e.force:navigateToURL will not work in Lightning Standalone App. 

You can drag this same component in lighnting Home page or Record Pages via app builder then it will work.

Thanks,
Maharajan.C
This was selected as the best answer
Mạnh NguyễnMạnh Nguyễn
var editRecordEvent = $A.get("e.force:editRecord");
                editRecordEvent.setParams({
                    "recordId": recId
                });
                editRecordEvent.fire();
                break;

And
var viewRecordEvent = $A.get("e.force:navigateToURL");
                viewRecordEvent.setParams({
                    "url": "/" + recId
                });
                viewRecordEvent.fire();
                break;


just run in a org,

sr for my question

Maharajan CMaharajan C
Not able to understand what you are asking.

Are asking where u have to run this component?
 
Mạnh NguyễnMạnh Nguyễn
As you say,

e.force:editRecord and e.force:navigateToURL will not work in Lightning Standalone App. 

thanks for support, Maharajan C
Ashish Zanzad 7Ashish Zanzad 7
Thanks Maharajan, you are Right.
I was also facing same issue, Now its working.