You need to sign in to do that
Don't have an account?
KIBL
Launch a visualforce page in Lightning
How can I auto lauch a visual force page in Lightning from an action button that calls a controller and redirects to a custom object and stays in lightning? I need all this to happen in one click.
We currently have a process that takes the values from the opportunity and populates a custom object. This process uses field ID's to map the values to a custom object. The existing button does not appear in "Lightning Experience." The only way that is obvious to accomplish this task in the "Lightning Experience" is to utilize a visual force page. The user should click a Lightning Experience "Action" button. The page should launch automatically, execute code in the controller and return to the visual force page to "navigatetoSObject." It is important that the user has a limited number of clicks that they have to execute. The "navigatetoSObject" is necessary so the user is not forced back into "Salesforce Classic" mode. If a PageReference is executed in the controller "Salesforce Classic" appears even though the user has chosen to be in the "Lightning Experience."
We currently have a process that takes the values from the opportunity and populates a custom object. This process uses field ID's to map the values to a custom object. The existing button does not appear in "Lightning Experience." The only way that is obvious to accomplish this task in the "Lightning Experience" is to utilize a visual force page. The user should click a Lightning Experience "Action" button. The page should launch automatically, execute code in the controller and return to the visual force page to "navigatetoSObject." It is important that the user has a limited number of clicks that they have to execute. The "navigatetoSObject" is necessary so the user is not forced back into "Salesforce Classic" mode. If a PageReference is executed in the controller "Salesforce Classic" appears even though the user has chosen to be in the "Lightning Experience."
And the Controller.
All Answers
you will need to use a additional javascript code to identify the environment in which your visualforce page is running [SalesForce Classic / Lightning Experience] by the sforce.one utility
function isLightningExperienceOrSalesforce1() {
return((typeof sforce != 'undefined') && sforce && (!!sforce.one));
}
if( isLightningExperienceOrSalesforce1() ) {
// Do something for Lightning Experience
}
else {
// Use classic Visualforce
}
and instead of PageReference or hardcoded string you could use $Action methods on your page.
The following trailheads could be helpful for you.
https://developer.salesforce.com/trailhead/lex_dev_visualforce/lex_dev_visualforce_multipurpose_pages
https://developer.salesforce.com/trailhead/lex_dev_visualforce/lex_dev_visualforce_process
Please mark this question if it helps and answered your question.
Thanks.
And the Controller.
I was able to get from those links the code: However, navigateToURL is superceded (according to: documentation (https://developer.salesforce.com/docs/component-library/bundle/force:navigateToURL/documentation)) by Lightning:navigate
components_navigation_web_page (https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/components_navigation_web_page.htm)
so the code becomes: Don't forget to put in your component definition.
By using different PageReference type, you can launch record pages, tabs, lists and more.