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
Peter BölkePeter Bölke 

Problem with Action undefined


we are on lightning and on a custom record page i have button which is linked to VF-Page. This page hold two lightning componenten and two VF-componnent.
I have an issue with the lightning components there is another button which shouuld open another component, but i fails with:
TypeError: Cannot read property 'setParams' of undefined

and this is the code what causes this exception:
var action1 = $A.get("e.force:navigateToComponent");
    componentDef: "c:LtngBusinessPotentialsViewAllComp", 
    componentAttributes: { 
        rId : component.get('v.recordId')

I don't know why this action is 'undefined'. This code work in other components.

Can you give me an advise?

Khan AnasKhan Anas (Salesforce Developers) 
Hi Peter,

Greetings to you!

If you are previewing through dev console force events are available only inside a container. Therefore launch your Component in LEX via app builder or lightning quick-action or drag to the detail page. As per Salesforce doc:

This event is handled by the container. It’s supported in Lightning Experience, the Salesforce app, and Lightning communities.

Also, starting in API version 43.0, the force:navigateToComponent event is deprecated. Salesforce recommends implementing the lightning:isUrlAddressable interface on your target component and navigating to the component using lightning:navigation component with the standard__component page type instead.

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas
Naveen KNNaveen KN
I think you need to replace action1 with action. try and let me know if that works.