15

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.

4
  • Not sure i get the intent of your visualforce page here. Why would you not drive your behaviour off a Lead Before trigger for example? I ask this coz I can't see a lot happening in your VF, unless you've cut it down to a bare minimum to post it. Commented Oct 31, 2012 at 19:35
  • When you use the detail tag and use inline edit it shows the save and cancel by default doesn't it? Why would you want to have a separate save button !!!! Am I missing something/ misunderstanding?! pic showing the issue
    – Rao
    Commented Oct 31, 2012 at 20:11
  • @rao we are talking about custom VF page here not default pages Commented Oct 31, 2012 at 22:57
  • @PrafullaPatil All I did was copy pasted the code posted and I saw the page rendered as I have pasted in the image. I see that with a inline edit option with the detail tab the save and cancel renders( unless the user does not have edit access on object!!) on the page and on hitting the save button the record gets saved.As soon as the save is complete, you can use an action support oncomplete and redirect the page
    – Rao
    Commented Oct 31, 2012 at 23:38

4 Answers 4

10

When you double click to inline edit, that doesn't create an input that is bound to the record in your controller via the viewstate, rather it creates a decoupled input on the fly and renders a save button that can save the record via a javascript call to sfdcPage.save().

You could attach some javascript to your Visualforce save button that locates the inline edit save button and if that exists, clicks it. You'd need to be able to detect that the save has completed and then complete your own save though, which I can only see happening by periodically checking for the inline edit save button disappearing. Also, if you were carrying out a save on the same record with other changes from your visualforce page, you'd need to retrieve the record anew from the database and merge your changes in. Add the fact that if the way that inline editing works were to change then your solution would suddenly stop working, and it doesn't look like a robust solution.

If you need the apex:detail behaviour, I'd be inclined to try to move the additional functionality based on field values to a trigger or scheduled apex.

1

Displaying the <apex:detail> component changes the way the Visualforce page interacts with the form elements on the page and the controller.

You will have an easier overriding the standard controller action by removing <apex:detail> and using Visualforce form elements instead:

<apex:page standardController="Lead" extensions="LeadTestExtensionController">
    <apex:form >
        <apex:commandButton action="{!save}" value="Save" id="btnSave"/>
           <apex:inputField value="{!Lead.Name}" />
           <apex:inputField value="{!Lead.Email}" />
           ...
    </apex:form>
    </apex:page>
2
  • This is exactly what the asker does not want to do (forgo the use of apex:detail) Commented Oct 31, 2012 at 21:35
  • 1
    I don't believe you can override it. At least I haven't seen it done. Messed with <apex:detail> a lot to try to get buttons to behave the way we wanted. For example it's the easiest way to get a Submit for Approval button and process a record for approval with a workflow. However, it's a very ridged element. If someone has a better explanation, I'd like to see it! Commented Oct 31, 2012 at 21:39
1

Try using saveURL.

I have somewhat of a similar requirement. In my case it's to redirect the user to a page after save is clicked (either inline edit.. forgot about that until I read this post) or save on the edit page. My solution is to utilize the saveURL to redirect the user after a save is performed. Basically I created a custom edit button that adds the saveURL onto the edit page and then when the VF page is called, I do some logic to redirect the user to an external page based on criteria of the record. It's convoluted, but worth checking out.

0

If you're trying to do a redirect post-save I've had success using an inline visualforce page that changes url with javascript on load.

<apex:page standardController="Account">
  <apex:outputPanel rendered="{!account.do_redirect__c}">
    <script>
      window.top.location.href = "/apex/my_redirect?id={!account.id}";
    </script>
  </apex:outputPanel>
</apex:page>

You can have a trigger determine if the redirect is needed and set your flag. If you only want to do the redirect once, you can puts some logic in the redirect page to uncheck the flag so the next time a user comes back to it they don't get redirected again.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .