function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
@altius_rup@altius_rup 

Override standard Save method called from standard Save button on standard Object (eg Opportunity)

Hi,

I have built this VF page :

 

<apex:page standardController = "Opportunity"
                   extensions = "RefreshPage"
          standardStylesheets = "true"
                   showHeader = "true"
           >
    
    <apex:detail subject="{!id}"  showChatter="true"  relatedList="false"  inlineEdit="true" />

    <c:ConditionsTarifairesV3 />

    <apex:relatedList list="OpportunityContactRoles"/>
    <apex:relatedList list="OpportunityPartnersFrom"/>
    <apex:relatedList list="OpenActivities"/>
    <apex:relatedList list="ActivityHistories"/>
    <apex:relatedList list="NotesAndAttachments"/>
    <apex:relatedList list="ProcessSteps"/>
    
</apex:page>

 

Basically, I replace the display and management of opportunity lines, but display the opportunity detail in the standard way, allowing for inlineEdit.

 

When a user updates a certain field (by inlineediting in the opportunity, I want to redisplay the whole page (opp + lines).

 

To do this, I just need to redefine the Save method of Opportunity in the RefreshPage controller extension : 

 

public class RefreshPage {
    public ApexPages.StandardController stdCtrl { get; set; }

    public RefreshPage(ApexPages.standardController std) {
        stdCtrl     = std;
    }

    // Overloading standard Opportunity save behaviour
    public PageReference save() {
        stdCtrl.save();
        System.Debug('#### RefreshPage : in save()');
        return Apexpages.currentPage();
    }
}

This does not work : the ines are not redisplayed, i.e the whole page is not redisplayed.

 

Any ideas why ?  Any other solutions ?

 

Thanks for you contributions,

Rup 

Best Answer chosen by Admin (Salesforce Developers) 
@altius_rup@altius_rup

Josh,

Thanks for your answer, which was 90% perfect, for what I am trying to do.

 

In the end, this is my solution :

    <script>
        sfdcPage.oldsave = sfdcPage.save;
        sfdcPage.save = function(id) {
            alert('ok');
            /* window.setTimeout('window.location.href = window.location.href',10); */
            window.setTimeout('window.location.reload(true);',10);
            this.oldsave(id);
        }
    </script>

 

location.reload forces the whole page to reload, as opposed to just refresh : the difference is that when the page reloads, my custom component is reinitialized, which reloads the opportunity lines (which change based on values in the opp).

 

Thanks for you help,

 

Rup

All Answers

joshbirkjoshbirk

I think the inlineEditing is saving the record with its own agenda, so to speak.  The save button there calls some JavaScript, i.e.:

 

sfdcPage.save('j_id0_j_id1');

 

To perform the save.  Whereas I think the save function itself is bound to the save() method - if that makes sense.  Inline Editing is a bit tricky like that (it also gets around the apex:form requirement, if that shows how "unbound" it is).

 

However, since this is JavaScript you could rehook the original function like so:

 

<script>
	sfdcPage.oldsave = sfdcPage.save;
	sfdcPage.save = function(id) {
		window.setTimeout('window.location.href = window.location.href',10);
		this.oldsave(id);
	}
	</script>

 

Which will retain the original function, insert your own code and then execture the old function.  I've got that snippet under my form tag (it could probably go at the bottom of your page) and it seems to behave.

 

Note that what I'm describing here is probably not technically "supported"... 

@altius_rup@altius_rup

Josh,

Thanks for your answer, which was 90% perfect, for what I am trying to do.

 

In the end, this is my solution :

    <script>
        sfdcPage.oldsave = sfdcPage.save;
        sfdcPage.save = function(id) {
            alert('ok');
            /* window.setTimeout('window.location.href = window.location.href',10); */
            window.setTimeout('window.location.reload(true);',10);
            this.oldsave(id);
        }
    </script>

 

location.reload forces the whole page to reload, as opposed to just refresh : the difference is that when the page reloads, my custom component is reinitialized, which reloads the opportunity lines (which change based on values in the opp).

 

Thanks for you help,

 

Rup

This was selected as the best answer