• Sergio López Calvo
  • NEWBIE
  • 0 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 3
    Replies
I've overridden "New" button of custom object with Visualforce page. When I click this button it should redirect to another one.app page in Salesforce1 but it's not working and says "Something has gone wrong. $A.getDefinition. Please try again."

My Visualforce page:
<apex:page standardController="Note__c" sidebar="false" showHeader="false" standardStylesheets="false" applyBodyTag="false" applyHtmlTag="false" showQuickActionVfHeader="false">
<script>
    var url = '/one/one.app#eyJjb21wb25lbnREZWYiIDogImM6cXVpY2tBZGQiLCJhdHRyaWJ1dGVzIiA6IHt9fQ==';
sforce.one.navigateToURL(url, true);
</script>    
</apex:page>

However, it's working when I do
window.parent.location = '/one/one.app#eyJjb21wb25lbnREZWYiIDogImM6cXVpY2tBZGQiLCJhdHRyaWJ1dGVzIiA6IHt9fQ==';

Any suggestions much appreciated.
Thanks.
Greetings!

sforce.one.navigateToURL() fails to navigate from Visualforce page tab to Lightning component tab. The issue started happening under Lightning experience since Winter 17 upgrade. It looks like something that should be fixed by Salesforce development on Salesforce side. Steps to reproduce are provided bellow.

Repro
~~~~~

1. Create a simple Lightning component with name "NavigateToURLTest" and the following code:
 
<aura:component implements="flexipage:availableForAllPageTypes,force:appHostable"
access="global"
>
<div style="text-align: center; font-size: 30px; padding-top: 100px;">
NavigateToURLTest Lightning Component
</div>
</aura:component>

2. Create a Lightning component tab with the same name "NavigateToURLTest" and add
it to Lightning navigation menu. 

3. Reload the app in a browser and click on the newly added "NavigateToURLTest" menu
item. After the component shows up copy a local part of a URL from browser address bar. This local URL will be used to navigate from Visualforce page. It should look like this:

/one/one.app#eyJjb21wb25lbnREZWYiOiJvbmU6YXVyYUNvbnRhaW5lciIsImF0dHJpYnV0ZXMiOnsidmFsdWVzIjp7InRhZyI6ImM6TmF2aWdhdGVUb1VSTFRlc3QifX0sInQiOjE0NzcxNzI5MTc1NjV9

4. Create a Visualforce page with the same name "NavigateToURLTest" and the following code:
<apex:page >
<div style="text-align: center; font-size: 30px; padding-top: 100px;">
NavigateToURLTest Visualforce page
</div>
<div style="text-align: center; padding-top: 30px;">
<button style="font-size: 20px; padding: 15px;" onclick="ntut_Navigate();">Click to Navigate</button>
</div>
<script type="text/javascript">
function ntut_Navigate() {
// NOTE: paste here local URL from step 3
var url = '/one/one.app#eyJjb21wb25lbnREZWYiOiJvbmU6YXVyYUNvbnRhaW5lciIsImF0dHJpYnV0ZXMiOnsidmFsdWVzIjp7InRhZyI6ImM6TmF2aWdhdGVUb1VSTFRlc3QifX0sInQiOjE0NzcxNzI5MTc1NjV9';
sforce.one.navigateToURL(url, true);
};
</script>
</apex:page>

5. Mark the Visualforce page as "Available for Salesforce mobile apps and Lightning Pages".

6. Create a VIsualforce page tab with name "NavigateToURLVisualforce" and add it to Lightning navigation menu.

7. Reload the app in a browser and click on the newly added "NavigateToURLTest" menu item. Then click on "Click to Navigate" button.

8. Actual result: an error "Something has gone wrong. $A.getDefinition. Please try again." is displayed and navigation does not happen.

9. Expected result: application navigates to "NavigateToURLTest" tab. This was working fine until Winter 17 upgrade.

10. Additional information: a result URL that the app navigates to has the following structure (after base64-url decoding):
 
{"componentDef":"eyJjb21wb25lbnREZWYiOiJvbmU6YXVyYUNvbnRhaW5lciIsImF0dHJpYnV0ZXMiOnsidmFsdWVzIjp7InRhZyI6ImM6TmF2aWdhdGVUb1VSTFRlc3QifX0sInQiOjE0NzcxNzI5MTc1NjV9","attributes":{"values":{"tag":"c:NavigateToURLTest"}},"t":1477172917565}

instead of correct initial value:
 
{"componentDef":"one:auraContainer","attributes":{"values":{"tag":"c:NavigateToURLTest"}},"t":1477172917565}

Workaround
``````````
There is no workaround.
Hi Everyone,
 
//Component: LightningNavigate
<aura:component implements="force:appHostable">
    <div id="aura-page">
        <div class="container">
            <ui:button label="gotoURL" press="{!c.gotoURL}" />
        </div>
        <div class="container">
            <ui:button label="navigate" press="{!c.navigate}" />
        </div>
    </div>
</aura:component>

//Controller
({
    gotoURL : function(component, event, helper) {
        helper.gotoURL(component);
    },
    navigate : function(component, event, helper) {
        helper.navigate(component);
    }
})

//Helper
({
    gotoURL : function (component, event) {
        var urlEvent = $A.get("e.force:navigateToURL");
        urlEvent.setParams({
          "url": "/006/o"
        });
        urlEvent.fire();
    },
    navigate : function(component,event) {
        var address = '/Salesforce.com+Inc/@37.793779,-122.39448,17z/';
        var urlEvent = $A.get("e.force:navigateToURL");
        urlEvent.setParams({
          "url": 'https://www.google.com/maps/place/' + address
        });
        urlEvent.fire();
    }
})

//App
<aura:application >
    <c:LightningNavigate />
</aura:application>

While running above code, I am getting following issue:

Something has gone wrong. Action failed: c$LightningNavigate$controller$gotoURL [TypeError: Cannot read property 'setParams' of undefined] Failing descriptor: {c$LightningNavigate$controller$gotoURL}. Please try again.

Can someone please help me to resolve it?

Thanks,
Amit