You need to sign in to do that
Don't have an account?
DEV SFDC 28
Refresh custom object's related list in Lightning from (classic) Visualforce page.
Salesforce experts,
I have following use case:
A custom object related to an Account.
The related list is added into Account's page layout.
From a custom button a Visualforce page is opened, which initializes the custom object, fills the values and saves it.
After clicking the confirm button on VF page, the user is redirected back to Account page.
Everything works as designed on SF Classic.
BUT on Lightning the related list is not updated, although the object is created successfully. First after clicking the related list or refreshing the page manuelly, new record is shown.
<apex:commandButton> contains action returning redirected PageReference is tried first:
VF page:
If commandButton action returns redirection (pageRef is set), JS in oncomplete is not triggered. None of the following works. Just for test purposes.
Aliasing controller method through <apex:actionFunction> then JS:
This is already an old question but no answer could be found by searching through the community/internet.
I really hope someone already found a workaround (without using Lighting component or event) and can help me out here.
Tried suggestions from these resources and much more, none of them works.
https://www.forcetalks.com/salesforce-topic/navigate-to-url-is-not-refreshing-the-page-in-salesforce-lightning/
https://developer.salesforce.com/forums/?id=906F0000000MGSsIAO
I have following use case:
A custom object related to an Account.
The related list is added into Account's page layout.
From a custom button a Visualforce page is opened, which initializes the custom object, fills the values and saves it.
After clicking the confirm button on VF page, the user is redirected back to Account page.
Everything works as designed on SF Classic.
BUT on Lightning the related list is not updated, although the object is created successfully. First after clicking the related list or refreshing the page manuelly, new record is shown.
<apex:commandButton> contains action returning redirected PageReference is tried first:
VF page:
...... <apex:commandButton value="AddList" action={!addList}"/> ......Controller:
...... public PageReference addList() { // Logic to create custom object. PageReference pageRef = new PageReference('/' + ApexPages.currentPage().getParameters().get('id')); pageRef.setRedirect(true); return pageRef; } ......
If commandButton action returns redirection (pageRef is set), JS in oncomplete is not triggered. None of the following works. Just for test purposes.
<apex:commandButton value="AddList" action={!addList}" oncomplete="alert('blabla');"/> <apex:commandButton value="AddList" action={!addList}" oncomplete="window.opener.location.refresh();"/> <apex:commandButton value="AddList" action={!addList}" oncomplete="sforce.one.navigateToSObject('objId');"/>
Aliasing controller method through <apex:actionFunction> then JS:
...... <script> function myComp() { addListAction(); sforce.one.navigateToURL('objId'); //alert('blabla'); } </script> <apex:actionFunction name="addListAction" action="{!addList}"/> <apex:commandButton value="AddList" oncomplete="myComp();"/> ......JS is triggered but no effect on Lightning.
This is already an old question but no answer could be found by searching through the community/internet.
I really hope someone already found a workaround (without using Lighting component or event) and can help me out here.
Tried suggestions from these resources and much more, none of them works.
https://www.forcetalks.com/salesforce-topic/navigate-to-url-is-not-refreshing-the-page-in-salesforce-lightning/
https://developer.salesforce.com/forums/?id=906F0000000MGSsIAO
Greetings to you!
I tried to research your problem and found some solution which might help you.
If you want to use your page in lightning only then you can use:
However, if you want to use your page in both classic and lightning then you can use getUiThemeDisplayed ()
These are the values:
Theme1—Obsolete Salesforce theme
Theme2—Salesforce Classic 2005 user interface theme
Theme3—Salesforce Classic 2010 user interface theme
Theme4d—Modern “Lightning Experience” Salesforce theme
Theme4t—Salesforce mobile app theme
Theme4u—Lightning Console theme
PortalDefault—Salesforce Customer Portal theme
Webstore—Salesforce AppExchange theme
So, you have to use if condition like this:
I hope it helps you.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.
Thanks and Regards,
Khan Anas
Thank you very much for your quick response.
I need to use the VF page in both Lightning and Classic. But no problem, I know how to distinguish and handle them differently. Your comment explained it also pretty well. The only problem is get e.g. Account detail page or related list refreshed.
Very interesting part from your suggestion is: I will try it and leave comment if it works.
Thank you again.
Based on @Khan's comment, aura.redirect() is called. But there is no statement shows how aura is initialized.
So some research. From Apex Developer Guide I could only find AuraEnabled Annotation, which exposes a method to Lightning Component: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_annotation_AuraEnabled.htm
Further search leads to following posts:
https://salesforce.stackexchange.com/questions/200888/what-is-aura-redirect
https://salesforce.stackexchange.com/questions/188191/is-using-the-aura-apex-class-supported
It seems like Doc is not available.
From GitHub there is info about Aura framework, unfortunately not related to SFDC Classic usage, but for e.g. Lightning Component.
Try in Org, using code like this won't cause problem by saving or compiling: But in runtime the following error occurs:
Therefor the question is still open.
Has anyone further information or hint about how Lightning record detail page can be refresh from Classic VF?
Thx.
Actually, this is a known issue. Visualforce Page reference id not working on Lightning.
Please refer to the below link for more information.
https://success.salesforce.com/issues_view?id=a1p3A0000001BrUQAU&title=visualforce-page-reference-id-not-working-on-lightning
And there is no workaround available. But it is in a review and we may get a solution for this soon.
I hope it helps you.
Kindly mark this as solved if the information was helpful.
Thanks and Regards,
Khan Anas
But the reference id is probably not the cause for this error.
Retried after your reply:
- no change is made to the code
- activated debugging
- the log contains correct id and no error
- but the error message kept shown
Probably aura.redirect() works only in Lightning Component context? It seems like the error is caused by:aura.redirect(pageRef); OR
System.Aura.redirect(pageRef); OR
system.Aura.redirect(pageRef);
Put any of these redirect() into previous "else" segment won't cause problem saving code to server. Only runtime.
Replace it with classic pageRef.setRedirect(true); no error page anymore, but the detail page is of corse not refreshed.
I have a similar problem. Did you found any solution.
Regards,
Sami