[SalesForce] Redirect back to the VF page

In Classic: There is a New button on the VF page. On click of this button default new record create a page of the custom object gets open. On saving of the record, the page gets redirected to the VF page(On which new button was clicked).
enter image description here

Now we converted this VF page to lightning experience and we are facing a problem following problem.
On click of New button on VF page, a pop-up appears to create a new record (custom object) but in the background, VF page redirects to the blank page. So when we save this record, we are not redirected to the previous VF page.

New Button:
enter image description here
Popup:
enter image description here

Code used in contoller for returning url in classic:

Schema.DescribeSObjectResult ppConfigObj = Priority_Points_Settings__c.sObjectType.getDescribe();
String url = ApexPages.currentPage().getUrl();
PageReference pageRef = new PageReference('/'+ppConfigObj.getKeyPrefix()+'/e?retURL='+url);
return pageRef;

On VF page, above function is called:

<apex:commandButton value="New" id="newButtonConfig" action="{!createNewPriorityPointConfig}"/>

Please suggest a solution to solve this issue.

Best Answer

In your code, you are setting the page reference as follows:

PageReference pageRef = new PageReference('/'+ppConfigObj.getKeyPrefix()+'/e?retURL='+url);

In particular, you are calling a method ppConfigObj.getKeyPrefix() that looks as though you're getting the object name or something from a map. It's not exactly clear what it is since you don't show that part of your code. For all I know it could be the full path to the page like: /Apex/thisVisualForcePageName.

I think what you want to be doing is one of two things. Either converting that button to an Action (the action would work the same in Lightning) or convert the link to the proper format that Lightning expects it to have; one that includes the Object Name. When constructing the button link, I think you probably want to do something like the following:

{!URLFOR( $Action.Case.NewCase, $ObjectType.Case )} 

See Constructing Effective Custom URL Buttons and Links in the Salesforce Documentation for more on this subject with additional details and considerations that might apply to your situation.