4

I have a Detail page button (VF page) and controller for it.

I used Pagereferenc method to take user to the record details page:

However, it works fine in the Classic, but not in Lightning.

    String url = '/'+engCloneCopy.id+'/e?retURL=%2F'+engCloneCopy.id;        
    return new PageReference(url);  

In Lightning, it will open up the edit page correctly, however once user saves the record, then page is blank and record gets updated in the background.

Expectation is that, once user save the record it should go back to the record detail page as it works in classic.

enter image description here Any thoughts?

1
  • Did you end up having any joy here? This is an issue we're facing too
    – Bigears
    Commented May 16, 2019 at 14:59

3 Answers 3

1
+50

You can try sforce.one for to achieve your ask. sforce.one.editRecord(​recordId) Opens the page to edit the record specified by recordId. It works very well in the Lightning and mobile app. You need to handle redirection separately for classic.

A sample working example is:-

<apex:page standardController="Account" lightningStylesheets="true">
    <script>
    function  openeditpage(){
        sforce.one.editRecord('001B000000sOeCCIA0');
    }
    </script>
    <apex:form>
        <apex:commandButton value="BacK" oncomplete="openeditpage()" rendered="{!$User.UITheme == 'Theme4d' || $User.UITheme == 'Theme4t'}" />
    </apex:form>
</apex:page>

The above codes check whether user in Lightning or mobile app and once he clicks on it, it will redirect him to the edit page after completion of action you have mentioned in command button.

The edit record popup will redirect you to detail page once you hit the save button.

enter image description here

1
  • Not sure why sforce.one isn't documented more as the solution to executing Lightning navigation from within Visualforce pages. It was a bit of a trick to figure out how to get the page to redirect after APEX action, but will make it work using parameters I believe. Thank you!
    – Paul N
    Commented Jun 19, 2019 at 15:03
0

Use StandardController edit method and replace YourObjectName__c with your correct object API.

return (new ApexPages.StandardController (new YourObjectName__c(Id=engCloneCopy.id))).edit();
1
  • no luck @Santanu Boral, same it is going to the blank page instead detail page.
    – Ajay
    Commented Jun 21, 2018 at 17:54
0

Try below code:

 PageReference pageRef = new PageReference('/'+"yourid here"); 

   return pageRef ;

Refer below Post:

Page Reference not redirecting properly

1
  • I already tried this, it goes to view page, but I wanted redirect to edit page first, after saving it should redirect to view page.
    – Ajay
    Commented Jun 21, 2018 at 17:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .