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
AndreiGAndreiG 

How to update records after clicking the button “Save”?

 

Hi!
 
I am using <apex:inlineEditSupport>. I can edit all the records which are displayed in the table. But....when I click the button Save it redirects me to its original tab without saving any changes to the records.
 
I am looking to accomplish the following: after clicking  “Save”  all the   changes  are updated and the page is refreshed.   
 
Thanks

 

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

I've recreated your scenario in my dev org, and it seems that inline editing doesn't like it if you don't use an outputfield to in the column.

 

Try the following changes:

 

 

<apex:page standardController="Catalog__c" recordSetVar="catalogs" sidebar="false" showHeader="false">
<apex:form >
<apex:pageBlock >
<apex:panelGrid columns="2">
      <apex:commandLink action="{!previous}">Previous</apex:commandlink>
      <apex:commandLink action="{!next}">Next</apex:commandlink>
    </apex:panelGrid>
<apex:pageBlockTable value="{!catalogs}" var="cat">
<apex:column>
   <apex:outputField value="{!cat.COD__c}"/>
</apex:column>
<apex:column>
   <apex:outputField value="{!cat.Product_Name__c}"/>
</apex:column>
<apex:inlineEditSupport event="ondblClick"/>
</apex:pageBlockTable>
<apex:pageBlockButtons > 
     <apex:commandButton value="Edit" action="{!save}" id="editButton" />
     <apex:commandButton value="Save" action="{!save}" id="saveButton" />
     <apex:commandButton value="Cancel" action="{!cancel}" id="cancelButton" />
     </apex:pageBlockButtons>  
</apex:pageBlock>
</apex:form>
</apex:page>

 

You will still end up on the home page, but when you navigate back you should see the updated data.  If you want to remain on the existing page, you'll need an extension controller that executes the parent standard set controller save and then redirects back to the current page.

 

 

All Answers

bob_buzzardbob_buzzard

Have you given your save button an action method that saves the record to the database?

 

e.g. if you are using a standard controller, that provides a save method for the record:

 

 

<apex:page standardController="Account">
  <apex:form>
     <!-- code here -->
     <apex:commandButton value="Save" action="{!save}"/>
  </apex:form>
</apex:page>

 

 

AndreiGAndreiG

Hi! Thanks for reply.

 

Yes, I have given to the save button an action method that saves the record to the database. The code is below:

 

 

<apex:page standardController="Catalog__c" recordSetVar="Catalog__c" sidebar="false" showHeader="false" >
<apex:form >
<apex:panelGrid columns="2">
      <apex:commandLink action="{!previous}">Previous</apex:commandlink>
      <apex:commandLink action="{!next}">Next</apex:commandlink>
    </apex:panelGrid>
</apex:form>
<apex:form >
<apex:pageBlock >
<apex:pageBlockTable value="{!Catalog__c}" var="cat">
<apex:column value="{!cat.COD__c}"/>
<apex:column value="{!cat.Product_Name__c}"/>
<apex:inlineEditSupport event="ondblClick" 
                        showOnEdit="saveButton,cancelButton" hideOnEdit="editButton" />
</apex:pageBlockTable>
<apex:pageBlockButtons > 
                <apex:commandButton value="Edit" action="{!save}" id="editButton" />
                <apex:commandButton value="Save" action="{!save}" id="saveButton" />
                <apex:commandButton value="Cancel" action="{!cancel}" id="cancelButton" />
            </apex:pageBlockButtons> 
</apex:pageBlock>
</apex:form>
</apex:page>
<apex:page standardController="Catalog__c" recordSetVar="Catalog__c" sidebar="false" showHeader="false" ><apex:form ><apex:panelGrid columns="2">      <apex:commandLink action="{!previous}">Previous</apex:commandlink>      <apex:commandLink action="{!next}">Next</apex:commandlink>    </apex:panelGrid></apex:form><apex:form ><apex:pageBlock ><apex:pageBlockTable value="{!Catalog__c}" var="cat"><apex:column value="{!cat.COD__c}"/><apex:column value="{!cat.Product_Name__c}"/><apex:inlineEditSupport event="ondblClick"                         showOnEdit="saveButton,cancelButton" hideOnEdit="editButton" /></apex:pageBlockTable><apex:pageBlockButtons >                 <apex:commandButton value="Edit" action="{!save}" id="editButton" />                <apex:commandButton value="Save" action="{!save}" id="saveButton" />                <apex:commandButton value="Cancel" action="{!cancel}" id="cancelButton" />            </apex:pageBlockButtons> </apex:pageBlock></apex:form></apex:page>

 Did I miss something?

 

AndreiGAndreiG

Actually, it redirects me to the home tab even if I click on Edit, Cancel button. I can not figure out where is the problem....

bob_buzzardbob_buzzard

Returning to the home tab is documented behaviour for the Standard Set Controller class, if there is no original page defined (which I think means if there is no retUrl parameter on the URL).

 

I'm wondering if its the fact that you've given the same name for the standard controller and recordsetvar:

 

 

standardController="Catalog__c" recordSetVar="Catalog__c" 

 

 

This may confuse the controller between the list of records being edited and the prototype record used for mass updates.

 

Try changing to the following and see if that helps - you'll need to change your value backing the pageBlockTable too.

 

 

standardController="Catalog__c" recordSetVar="catalogs" 

 

 

 

 

AndreiGAndreiG

 

Hi! Thank you for your reply! 
I've tried. In this case it doesn't show any records. Still... it doesn't matter.... Once I click on any of the button it redirects me to the Standard Home Tab.  
I can not figure out where is the problem - in the settings of this custom object or in the code.... 
At this link it is a print screen after using "catalogs" as recommended:
Thanks!

 

 

bob_buzzardbob_buzzard

It won't show any records in this case as the variable backing the table is that of the prototype object, Catalog__c.

 

You'll need to change your pageblock to:

 

 

<apex:pageBlockTable value="{!catalogs}" var="cat">

 

 

in order to display the existing records.  

 

Returning to the home page is expected behaviour - both the cancel and save methods from the standard set controller will send you back to the home page.  If you make the change above, you should be able to update your records as part of that.

AndreiGAndreiG

 

Hi Thanks again for your reply. Yes, I have changed my pageblock and the existing records are displayed.

 

Still....after clicking any of the buttons it redirects me to the Standard Home Page and it doesn't save changes to the record, even if I click Save.  What should I do? 

 

 

<apex:page standardController="Catalog__c" recordSetVar="catalogs" sidebar="false" showHeader="false">
<apex:form >
<apex:pageBlock >
<apex:panelGrid columns="2">
      <apex:commandLink action="{!previous}">Previous</apex:commandlink>
      <apex:commandLink action="{!next}">Next</apex:commandlink>
    </apex:panelGrid>
<apex:pageBlockTable value="{!catalogs}" var="cat">
<apex:column value="{!cat.COD__c}"/>
<apex:column value="{!cat.Product_Name__c}"/>
<apex:inlineEditSupport event="ondblClick"/>
</apex:pageBlockTable>
<apex:pageBlockButtons > 
     <apex:commandButton value="Edit" action="{!save}" id="editButton" />
     <apex:commandButton value="Save" action="{!save}" id="saveButton" />
     <apex:commandButton value="Cancel" action="{!cancel}" id="cancelButton" />
     </apex:pageBlockButtons>  
</apex:pageBlock>
</apex:form>
</apex:page>

 

bob_buzzardbob_buzzard

I've recreated your scenario in my dev org, and it seems that inline editing doesn't like it if you don't use an outputfield to in the column.

 

Try the following changes:

 

 

<apex:page standardController="Catalog__c" recordSetVar="catalogs" sidebar="false" showHeader="false">
<apex:form >
<apex:pageBlock >
<apex:panelGrid columns="2">
      <apex:commandLink action="{!previous}">Previous</apex:commandlink>
      <apex:commandLink action="{!next}">Next</apex:commandlink>
    </apex:panelGrid>
<apex:pageBlockTable value="{!catalogs}" var="cat">
<apex:column>
   <apex:outputField value="{!cat.COD__c}"/>
</apex:column>
<apex:column>
   <apex:outputField value="{!cat.Product_Name__c}"/>
</apex:column>
<apex:inlineEditSupport event="ondblClick"/>
</apex:pageBlockTable>
<apex:pageBlockButtons > 
     <apex:commandButton value="Edit" action="{!save}" id="editButton" />
     <apex:commandButton value="Save" action="{!save}" id="saveButton" />
     <apex:commandButton value="Cancel" action="{!cancel}" id="cancelButton" />
     </apex:pageBlockButtons>  
</apex:pageBlock>
</apex:form>
</apex:page>

 

You will still end up on the home page, but when you navigate back you should see the updated data.  If you want to remain on the existing page, you'll need an extension controller that executes the parent standard set controller save and then redirects back to the current page.

 

 

This was selected as the best answer
AndreiGAndreiG

Thanks! The changes are saved after clicking the button. Now....I need to resolve with the extension.