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
dfpittdfpitt 

Using {!save} from an apex button during inline editing

Hello,

 

I have a VF page that simply shows the detail of a custom object with inline editing enabled. I added an apex button that is calling the {!save} method. But, if i change a field and click the button, the page simply refreshes and I lose the changes. Why is the {!save} method not saving?

 

<apex:page standardController="CustomObject__c" showHeader="false" sidebar="false" >
    <apex:form >
        <apex:commandButton action="{!save}" value="TEST SAVE" id="TESTSAVE" />
        <apex:detail inlineEdit="true" relatedList="true" relatedListHover="true" />
    </apex:form>
   
</apex:page>

Navatar_DbSupNavatar_DbSup

Hi,


You have seen that when you have enable inlineedit option inside the <apex:detail> you are getting a Save and Cancel button whenever editing that record. So you have to use that standard method to save the record. But if you want that record to be saved on click of your commandbutton you have to write the controller in which write the code as per your requirement.

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

dfpittdfpitt

Thanks for your reply.

 

I tried doing that, but I'm seeing the same behavior, the page refreshes to the old value. Here is the code I wrote:

 

public class CustomObjectExtension {
    public ApexPages.StandardController stdCtrl {get; set;}
    
    public CustomObjectExtension (ApexPages.StandardController controller) {
      stdCtrl=controller;
    }
    public void SaveObject(){
        stdCtrl.save();
    }
}

 

How can I capture the changes from inline editing to save them?

Devendra@SFDCDevendra@SFDC

Hi dfpitt,

 

If you are using <apex:detail inlineEdit="true"> then this option itself gives you two buttons "Save" and "Cancel". You dont require do create these buttons again. These buttons can handle standard Save and Cancel actions.

 

Hope this helps.

 

Thanks,

Devendra

 


dfpittdfpitt

Hi Devendra,

 

I do realize that I have those buttons available.

 

I'm trying to achieve something more complicated, as i'm trying to call the save function from another button. That button does other things as well, besides saving.

 

So, I simplified the issue to test it out first, but the save itself is not working.

 

Any other ideas of why the code above is not working?

 

Thanks!

 

dfpitt

Devendra@SFDCDevendra@SFDC

Hi dfpitt,

 

Try this,

 

You will have to retrieve record which you want to use in save method.

 

For e.g.

 

Id studentId=ApexPages.CurrentPage().getParameters().get('id');

 

Student__c st=[Select Id,Name from Student__c where Id=: studentId];

 

st.Name='New Name';

 

update st;

 

Hope this helps.

 

Thanks,

Devendra

dfpittdfpitt

Thanks Devendra,

 

But how do I get the name field from the screen, instead of hardcoding it in APEX?. The user is going to double click on a field and change it, before saving, he is going to click on my button, and my button should save the changes and then do other stuff?

 

Regards,

 

dfpitt

Andy BoettcherAndy Boettcher

dfpitt,

 

What are you "trying to make more complicated"?  What you are seeking to do is kind of pushing the envelope of what you can expect to be able to do from the inline edit page - but if you tell us what you're trying to ultimately accomplish, we may be able to propose an alternative approach?

 

-Andy

dfpittdfpitt

Hi Andy,

 

I have a Visualforce page with 3 Iframes.

 

One of these iframes is showing a proprietary page that I wont describe in detail, unrelated to salesforce.

 

Each of the other two iframes are showing the detail page of a custom object in salesforce with inlineEdit activated. Each one of these two custom objects has about 6 related lists (also custom objects).

 

The Visualforce page only shows one of the custom object Iframes at a time, and I have an apex commandbutton that toggles from one to the other. I want to save any pending changes in the iframe when I press the toggle button. So that the users don't lose changes by forgetting to click the standard Save button (and forgetting to press enter twice, which achieves the same thing).

 

To do this, I planned to call the standard {!save} method (or the one I coded in the APEX controller).Basically, I want to mimic what happens when the user clicks on the save button during inline editing.

 

I am able to call the save method as I click the button (I know its being called because I have javascript alerts surrounding the method, and both alerts are showing up), but the page simply refreshes without saving the changes.

 

I need to use InLineEdit, because I can't customize the Edit page, and I dont want the header and sidebar to be visible in the Iframe.

 

So, I simplified the problem, to what I described above, to be able to test it in a simpler environment. If I can achieve what's described above, then I can achieve what I described here.

 

Any ideas would be greatly appreciated.

 

Regards,

 

dfpitt

Andy BoettcherAndy Boettcher

Thank you for that explanation!

 

Let me tinker with this a tad - I'll let you know what I come up with.

 

-Andy

dfpittdfpitt

Any other ideas? Andy? SFDC Community?