I have a command link button on Account page (Create Account). As soon as a user clicks on the button, an edit page gets populated to fill the details. Once the details are filled and hit the save button, then account gets created and redirects the user to the account record detail page that got created. This works in Visualforce but if I switch to Lightning it doesn't redirect me to the detail page of the created record but remains on the same account page, but record gets created in Lightning as well.

The expectation is that once the record is saved , it should go to the record detail page as it works smoothly in classic but not in lightning

Apex controller:

return new pagereference('/'+acc.Id+'/e?&nooverride=1&saveURL=/apex/Address_Validation?addressType=AccountBillingAddress&id='+acc.Id+'&retURL='+acc.Id);

enter image description here


You can't utilize retURL in Lightning and I think the best answer would be to look at using a quick action on the account which can pre-populate the fields based on the current record and then displays a toast message with a link to click into the new record. You're on Lightning now so you should look at catering your customization/actions to fit the platform.

For Spring 20 coming out in a couple weeks, they actually did bring back some ability to do the pre-filling notion using a custom button/link. You can test this out in a sandbox with Spring 20 to see if it meets your needs. Below, is the example of the formula and what you can do:

    CustomCheckbox__c={!IF(Account.SomeCheckbox__c, true, false)}

If you do need to simply edit the VF page to support some of that functionality, you could look at this trailhead on the difference in navigation in Lightning vs. Classic as well.

Essentially, in Lightning there's an event mechanism for navigation and messaging. This is exposed in Visualforce as a JavaScript object called sforce.one. You could use the sforce.one.editRecord(); method to pass the accId and it'll redirect you to the edit screen and automatically go on that record after the save. The missing piece is that I don't believe there's a way to pass field information to pre-fill.

  • Do you mean because of using retURL the page reference isn't redirecting to the record detail page. If yes, then for just redirection purpose I have to migrate whole vf page to lightning??
    Jan 26 '20 at 8:01
  • If the VF page is just doing what you showed us (prefilling some fields in the create screen and redirecting) then it's simply just creating a quick action on Accounts to create accounts with pre-defined fields. Jan 26 '20 at 12:40
  • I also added an edit as they did add something in Spring 20 for Lightning that could meet your needs. Jan 26 '20 at 12:53
  • No, the VF page contains alot of stuff apart from the command link code snippet i have provided. Also the spring 20 link you have mentioned is for the record creation with default values but i am struggling with page redirection. I tried sforce.one, but this doesn't work for me.
    Jan 30 '20 at 13:42
  • What you showed in the question is answered by utilizing a quick action or looking at the new feature in Spring 20. There's no need to re-direct as, when I tested in Spring 20, it does it for you. The quick action doesn't auto-redirect but provides a toast with a link to click onto the new record. If your page is more complicated than what you provided in the question, then you'll need to go through that and break it down. Jan 30 '20 at 14:13

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.