[SalesForce] Get record ID using ApexPages.StandardController in lightning enabled org

I have old apex controller which has constructor implemented as follows:

public class RetrieveRecordId{
   Id recordId;
   public RetrieveRecordId(ApexPages.StandardController controller) {
     recordId = controller.getId();
   }
}

Now this was working fine in salesforce classic, but when org was switched to lightning ApexPages.StandardController does not get the recordId when a url na15.salesforce.com/apex/RetrieveRecordIdPage?id=a0o58000000a8qJAaQ .

I know lightning URL don't know what parameters are being passed. Is there any workaround to get params with existing apex code without changing to aura enabled controllers.

Best Answer

It is not an issue about Visualforce not able to passing the record Id. It is about you can't open a Visualforce page by just putting the url in the location bar in lightning experience.

In short, lightning experience is a single page app, so every visualforce page is treated as an iframed component, instead of a separate page. So you can't simply put the url in the location bar to open the page.

Instead, you need to type the below javascript in your console to navigate to your visualforce page:

$A.get("e.force:navigateToURL").setParams(
    {"url": "/apex/pageName"}).fire();

For more information, refer to this trailhead: https://trailhead.salesforce.com/lex_dev_visualforce/lex_dev_visualforce_process