Edit : You can proxy the invocation of the Standard Save method via an ActionFunction, but then override the redirect by using the onComplete to redirect to a custom URL. Here is a sample I did for overriding the New button for Contact : (By default the Save method returns you to the Contact newly created, however using this I managed to get it to return to the Account I clicked the New Contact button on)
<apex:page standardController="Contact">
<script>
var returnURL;
window.onload = function(){
returnURL = gup('retURL');
//alert('Set retURL = ' + returnURL);
};
function gup( name ){ //this function just grabs HTTP params by name
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regexS = "[\\?&]"+name+"=([^&#]*)";
var regex = new RegExp( regexS );
var results = regex.exec( window.location.href );
if( results == null ) return "";
else return results[1];}
function redirectBack(){
//alert('Sending you back to ' + returnURL);
window.location.href = '/' + returnURL;
}
</script>
<apex:form >
<apex:actionFunction name="saveActionFunc" action="{!Save}" oncomplete="redirectBack()" rerender="theBlock" />
<apex:pageBlock mode="Edit" id = "theBlock" >
<apex:pageBlockButtons >
<apex:commandButton value="Save" onClick="saveActionFunc();"/>
</apex:pageBlockButtons>
<apex:pageBlockSection >
<apex:inputField value="{!Contact.LastName}" />
<apex:inputField value="{!Contact.FirstName}" />
<apex:inputField value="{!Contact.Email}" />
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
In summary, it does seem possible to do without a Controller! (Although I noticed some javascript race issues at times, but works for the most part)
My understanding of retURL is the location you want to redirect to when the user hits Cancel. To control the page to navigate to on Save, the saveURL is used.
When creating a new record from inspecting the URL, it also adds save_new_url=/003/e for Contact. I would try adding this.
Could you post the URL you have set the new button to redirect the user to when they click new.
(what I usually do is copy the URL that salesforce by default sends you to when clicking new)
I would also try adding noOverride=1 to the URL.
I finally figured this out. This is actually a known issue between VF and background Apex changes (thanks Salesforce), along with navigation back to a Standard Page via PageReference:
https://success.salesforce.com/issues_view?id=a1p3A0000001C8QQAU&title=data-not-updated-in-ui-after-an-apex-update-in-lightning-experience
I found this Post that explained how to use remoting to force the refresh (in Lightning):
https://www.sales4k.com/sfdc/salesforce-lightning-refresh/
Unfortunately, that also did NOT (or no longer does) work either. It did however lead me to Googling caching issues with sforce.one.navigateToSObject in Lightning, where I found a Post that said sforce.one.back(true) does work in Lighting. Finally, I got it to work, using this approach. The following example illustrates my final solution:
Visual Force .page file:
<apex:page controller="YOUR_CONTROLLER" action="{!Launch}" cache="false"
lightningstylesheets="true">
<script src="/soap/ajax/38.0/connection.js" type="text/javascript"></script>
<script src="/soap/ajax/38.0/apex.js" type="text/javascript"></script>
<script type="text/javascript">
// Back NAV.Refreshed
sforce.one.back(true); // While sforce.one.navigateToSObject(YOUR_ID) did NOT
// refresh, sforce.one.back(true) did refresh
</script>
</apex:page>
Apex Controller
global class YOUR_CONTROLLER
{
public void Launch()
{
// Your update logic goes here (will properly refresh on backward navigation)
...
}
}
Best Answer
If you click overriden button and look at your URL, you will see:
So in your controller read this parameter:
And after everything is complete do return: