Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

Currently in my VF Page (inline editing support enabled) after clicking "Save" button, I am being taken to the default detail page layout.

I want "Save" operation to be executed upon clicking the "Save" button but make the user stay on the same page.

Can someone tell what should I do ?

My Code :

<apex:page standardcontroller="Expense__c" sidebar="false" showHeader="true" showChat="false"  >
<apex:form >

<apex:inlineEditSupport />
<apex:commandButton action="{!save}" value="Save" id="theButton"/>
<apex:pageBlock title="List of Expenses">
<apex:pageBlockTable value="{!Expense__c}" var="item" >
<apex:column value="{!item.Date__c}"/>

<apex:column value="{!item.Type__c}"/>
<apex:column value="{!item.Amount__c}"/>
<apex:column value="{!item.Comments__c}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
share|improve this question
    
Have you overridden the buttons in the salesforce configuration on the object? –  Francis Apr 13 at 10:09

1 Answer 1

up vote 3 down vote accepted

It looks like your page invokes the standard controller's default save method that returns the default detail page URL. To change that URL you can write your own save method that first invokes the standard controller's save to do most of the work and then returns a page URL of your choosing:

public with sharing class ExpenseController {
    private ApexPages.StandardController sc;
    public ExpenseController(ApexPages.StandardController sc) {
        this.sc = sc;
    }
    public PageReference save() {
        PageReference detailPage = sc.save();
        if (detailPage != null) {
            // Construct URL of edit page or whatever other page you want
            PageReference editPage = new PageReference(detailPage.getUrl() + '/e');
            return editPage;
        } else {
            return detailPage;
        }
    }
}

Include the name of the controller extension in the page:

<apex:page standardcontroller="Expense__c" extensions="ExpenseController" ...
share|improve this answer
    
Is it possible to have the quicksave function in the above code? That would be very handy too.. –  MnZ Jun 19 at 4:49
    
@MnZ The standard controller has a quickSave method you can invoke from an extra "Quick Save" button. –  Keith C Jun 22 at 15:48

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.