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
Shivam DashShivam Dash 

how to save the recod and redirect to another vf page when click on save button

Hi i want to save the record and redirect to another vf page when clcik on save button . i am able to redirect to vf page but its not saving the record . i am posting the code please anyonre help me out what i am missing .

<apex:page standardController="Account" recordSetVar="Accounts" id="thePage" showHeader="true" sidebar="false" extensions="extension1" >
  <apex:form >
        <apex:pageBlock >
            <apex:pageBlockTable value="{!Accounts}" var="Acc">
                <apex:column value="{!Acc.name}"/>
                  <apex:column headerValue="Account Number">
                    <apex:inputField value="{!Acc.AccountNumber}"/>
                  </apex:column>
                  <apex:column headerValue="Phone">
                    <apex:inputField value="{!Acc.Phone}"/>
                  </apex:column>
            </apex:pageBlockTable> 
              <apex:inlineEditSupport />
          <apex:pageBlockButtons >
              <apex:commandButton value="Next" action="{!Next}" id="saveButton" reRender="none" />
</apex:pageBlockButtons>
      </apex:pageBlock>
  </apex:form> 
</apex:page>


----------------------------------------------------

public class  extension4 {
private ApexPages.StandardController controller;
    public  extension4 (ApexPages.StandardSetController controller) {
      
    }
   
    public PageReference Next(){
       
        controller.save();
        PageReference reRend = new PageReference('/apex/mypage22');
        return reRend;
    }
}
 
Shun KosakaShun Kosaka
Hi,
Modify the type of variable "controller" and constructor. 
private ApexPages.StandardSetController controller;
    public extension4 (ApexPages.StandardSetController controller) {
      this.controller = controller;
 }
This makes the variable controller have standard controller and then record can be saved in your method.
And perhaps extension4 is typo of extension1? (it's inconsistent with apex:page tag)
 
Shivam DashShivam Dash
Hi Shun ,
I tried this one but not getting save the record .
miss printed of that extension 4 instead of extension 1 .
Shun KosakaShun Kosaka
Hi Shivam,
It's weird.. I will provide a sample DE org that implements above code soon!
Shun KosakaShun Kosaka
Hi Shivam,
Sorry for late. Had some trouble logging in this forum. Try below env.
ID : shivam.dash@de.test
Pass : S@lesforce1
I created /apex/TestAccountList and dummy mypage22.