2

I have overridden standard new button with a Visualforce page, after clicking save from that visualforce page, its redirecting to the standard edit page and on save from the standard edit page it should redirect to detail page of that record.

For Salesforce classic, its working as expected but in lightning experience, from standard edit page its not redirecting to detail page of that record.

On save I am calling controller's method and setting the redirectURL to standard edit URL and oncomplete using handleRedirect() function

<apex:commandButton action="{!save}" oncomplete="handleRedirect();" value="Save and Continue" rerender="pgMsg"/>

function handleRedirect() {
    var redirectURL = '{!redirectURL}';
    if (redirectURL != null && redirectURL != '') {
        if ((typeof sforce != 'undefined') && (sforce != null)) {
            sforce.one.navigateToURL(redirectURL);
        } else {
            window.location.href = redirectURL;
        }
    }
}
2
  • Can you share your code Nov 23 '16 at 18:35
  • @Santanu On save I am calling controller's method and setting the redirectURL to standard edit URL and oncomplete using handleRedirect() function <apex:commandButton action="{!save}" oncomplete="handleRedirect();" value="Save and Continue" rerender="pgMsg"/> function handleRedirect() { var redirectURL = '{!redirectURL}'; if (redirectURL != null && redirectURL != '') { if ((typeof sforce != 'undefined') && (sforce != null)) { sforce.one.navigateToURL(redirectURL); } else { window.location.href = redirectURL; } } }
    – Tiny
    Nov 23 '16 at 18:56
0

Can you try out like this:

sforce.one.navigateToSObject(recordId) to navigate from lightning

Before that retrieve the recordId as use that in your code

if((typeof sforce != 'undefined') && sforce && (!!sforce.one))
{
   sforce.one.navigateToSObject(recordId,edit);
}
7
  • Tried that as well but still not working.
    – Tiny
    Nov 23 '16 at 19:19
  • are you using 18 digit Id? Nov 23 '16 at 19:25
  • Yes, I am using 18 digit Id
    – Tiny
    Nov 23 '16 at 19:27
  • On save from visualforce page it redirects to standard edit page by using handleRedirect() method In Lightning experience, the standard edit page opens as a popup and from that the save is not redirecting to detail page.
    – Tiny
    Nov 23 '16 at 19:34
  • updated answer with 'view' parameter Nov 23 '16 at 19:41
0

Import Connection.js file

<apex:includeScript value="/soap/ajax/43.0/connection.js"/>

Set session Id to sforce

sforce.connection.sessionId = "{!$Api.Session_ID}";

Than run below code:

sforce.one.navigateToURL(redirectURL);
0

Since it's opening a Pop-up, So for the current context that pop-up is the window and it is trying to redirect the Pop-up window which will not work at all.

try to do as...

window.top.location.href = redirectURL;

but put a check for UI as well, do it only if current UI is lightning. You have methods to check for UI in Apex.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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