How do I properly override salesforce standard object controller save method to intercept it in a visual force page?

10,332

Calling save() on the standard controller does not commit inline edits in a detail section. I've just reproduced the problem using only the standard controller, so the way you are overriding it is not the issue.

I think the reason for this is that apex:detail gets a record out of the database in its own right, rather than using a reference to the one in the standard controller.

Inline edit should provide you with its own save button, and I think your best bet is to try and incorporate that into your design.

Share:
10,332
atbebtg
Author by

atbebtg

Updated on July 27, 2022

Comments

  • atbebtg
    atbebtg almost 2 years

    Hi there I created a visual force page to with a standard lead controller as the controller and extend it. I want to do this so i can still utilize the apex:detail control and not reinvent the wheel in dealing with the standard lead info, related list etc.

    I added an apex:commandbutton and make it call save. When I click on this button I can clearly see that my function is being called. However, all changes that is done to the lead info via inline editing is not captured.

    For example, If I edited LastName using the inline editing and i click on the apex:commandbutton the new LastName value is not being saved. It's almost like the save function that is being called by apex:commandbutton is not aware of the data changes.

    the following is code to my visual force page.

    <apex:page standardController="Lead" extensions="LeadTestExtensionController">
    <apex:form >
        <apex:commandButton action="{!save}" value="Save" id="btnSave"/>
        <apex:detail subject="{!Lead.Id}" relatedList="true" showchatter="true" inlineEdit="true" />
    </apex:form>
    </apex:page>
    

    the following is code to my controller public with sharing class LeadTestExtensionController { private Apexpages.StandardController controller; private PageReference page; private string id; private final Lead myLead; public String positions {get; set;}

    public LeadTestExtensionController(ApexPages.StandardController stdController) {
        this.controller = stdController;
        this.myLead = (Lead)stdController.getrecord();
        this.page = ApexPages.currentPage();
        this.id = page.getParameters().get('id');
        List<Lead> myLeads = [select Opportunity_Stage__c from lead where id = :id];
        if(myLeads.size() > 0)
        {
            positions = myLeads[0].Opportunity_Stage__c;
        }
    }
    
    public PageReference save() {
        this.controller.save();
        PageReference newPage = New PageReference('/apex/RCS');
        newPage.getParameters().put('id',ApexPages.currentPage().getParameters().get('id'));
        newPage.setRedirect(true);
        return newPage;
     }
    

    }

    Once I click on the apex:command button, the page is being redirected to apex/RCS so i know its being called. However, if i return to the same lead, the last name doesn't change. I was under the impression that the following line would've called the standard controller's save function that should've taken care of the updating of the Last Name.

    this.controller.save();
    

    What am I doing wrong and how can I accomplish this. The above code is heavily simplified version of my actual code. What I am trying to do in my actual code is to check the value of certain field and if it meets certain criteria I want it to do something. However, I can't seems to see the new value entered.

    Thank you.

  • atbebtg
    atbebtg about 12 years
    The problem with inline edit own save button is that i can't intercept it unless i'm using trigger to check for the value changes. However, I can't do any redirect from within trigger. Thanks though.