-1

I have vf page:

  <apex:page standardController="case" extensions="Gss_CsHelathCheckExtension"  recordsetVar="lstAllUserData" sidebar="false" showHeader="false">
<apex:includeScript value="/lightning/lightning.out.js" />
<apex:includeLightning />
<div id="lightning" />
<script>
var myList = {!lstSelUserDataIds}; 
$Lightning.use("c:GSS_CsHealthCheck", function(){
    $Lightning.createComponent(
        "c:Gss_CaseHealthCheck",
        {caselist :myList},
        "lightning",
        function(cmp){
            $A.eventService.addHandler({
                event: 'force:navigateToObjectHome',
                handler: function(event) {
                    if (sforce && sforce.one) {
                        // VF page in S1 or Lightning Exp
                        sforce.one.navigateToObjectHome(event.$params$.scope);
                    } else {
                        // VF page in Classic
                        // Ugg! We need an if branch for each possible object type.
                        // Is there a better way of doing this?
                        if (event.$params$.scope === 'Case') {
                            window.location = '{!URLFOR($Action.Case.Tab, $ObjectType.Case)}';
                        }
                    }
                }
            });

        });
});
</script>

GSS_CsHealthCheck

<aura:application access="GLOBAL" extends="ltng:outApp" >
<aura:dependency resource="c:GSS_CaseHealthCheck"/>
  <aura:dependency resource="markup://force:*" type="EVENT"/>
 </aura:application>

GSS_CaseHealthCheck.CMP

<lightning:button variant="brand" label="Cancel" onclick="{!c.CancelPage}" />

Js:

CancelPage:function(component,event,helper){ 
    //window.history.back();
    var event = $A.get('e.force:navigateToObjectHome');
    event.setParams({
        scope:'Case'
    });
    event.fire();
}

ERROR:

This page has an error. You might just need to refresh it. Action failed: c:GSS_CaseHealthCheck$controller$CancelPage [Cannot read property 'scope' of undefined] Failing descriptor: {c:GSS_CaseHealthCheck$controller$CancelPage}

I have refereed below post:

https://joebuschmann.com/salesforce-lightning-navigation-events-in-a-visualforce-page/

0
2

Based on your previous questions, you are surfacing this component in a Lightning Out Visualforce container. This is an important detail that significantly changes component support, behavior, and troubleshooting. Please include that information in your questions where it is relevant to ensure that valid solutions can be found.

When you are working in Lightning Out, it's important to check the Lightning Component Library to find out whether or not the events and components you are using are supported in that context. In this case, you'll see under force:navigateToSObject that

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

Lightning Out is not part of the one.app container, even if your Visualforce page is being shown in Lightning Experience, and therefore does not support the event.

2
  • Duplicate of urlEvent is undefined
    – glls
    Feb 13 '19 at 1:05
  • Yes. simple solution will be passing current filter url to Lightning component & using window.location just redirect it Feb 14 '19 at 11:31
1

Maybe take a look here: https://joebuschmann.com/salesforce-lightning-navigation-events-in-a-visualforce-page/

Basically you need VF to have a custom handler for the event.

3
  • hi charles, remember to post the essentials of te link, otherwise it might be flagged as a link only answer and deleted
    – glls
    Feb 12 '19 at 14:08
  • I have updated the question and same problem. many people engagged to this question So I updated it. Feb 12 '19 at 16:59
  • Duplicate of urlEvent is undefined
    – glls
    Feb 13 '19 at 1:05

Not the answer you're looking for? Browse other questions tagged or ask your own question.