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
AnnaTAnnaT 

After clicking [save] button

I created save button.

If I click this button, the page jumps to Dashbords page.

How can I set page direction?

 

 

 

<apex:form >
<apex:commandButton action="{!save}" value="Save" id="theButton" /><br></br>

<body>

 

 

Shashikant SharmaShashikant Sharma

Does your VFP has any standard controoler?

Are you using standard save or overrided it i your class?

Please answer aove questions?

AnnaTAnnaT

Dear Shashikant Sharma,

 

>Does your VFP has any standard controoler?

No, this save button only.

 

>Are you using standard save or overrided it i your class?

I'm using standard save.

 

Thank you for your cooperation.

 

Anna

AnnaTAnnaT

Sorry, maybe I misunderstood the meaning of standard controller.

 

I'm using standard controller which references my custom object.

 

 

<apex:page standardStylesheets="true" showHeader="True" sidebar="false" standardController="CR_CO__c" recordSetVar="crco"  tabstyle="CR_CO__c"> 

 

 

Shashikant SharmaShashikant Sharma

I would suggest you to override the save in a extenstion class then you can redirect your page as per you requiremnt.

 

pibic PageReference save() {

 

     upsert yuorObjectsinstace;

     PageReference p = new PageReference(URL where you want to redirect);

     return p;

 

}

Chamil MadusankaChamil Madusanka

Hi,

 

You cannot set your own redirection in standard save method. you have to create your save method in a apex class and name it as the extention of your VF page.

 

Controller(Extention)

 

public class MyController{        
    private final CR_CO__c crco;
        
    public status(ApexPages.StandardController stdController) {
        this.crco=(CR_CO__c)stdController.getRecord();
    }        
     public PageReference saveApp() {
         
            try{
                   insert(crco);                                                
             }catch(System.DMLException e){
                ApexPages.addMessages(e);
                 return null;
        }  

                 PageReference p = Page.Confirmpage;//Confirmpage is another VF page
                  p.setRedirect(true);
                  return p;                              
     }    
}

 

 

 

<apex:page standardStylesheets="true" showHeader="True" sidebar="false" standardController="CR_CO__c" extensions="MyController" recordSetVar="crco"  tabstyle="CR_CO__c"> 

 

<apex:form >
<apex:commandButton action="{!saveApp}" value="Save" id="theButton" />

If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.

 

Chamil's Blog

kiranmutturukiranmutturu

to which page that you want to redirect or want to stay there on the same page or what?

Jake GmerekJake Gmerek

Another approach you could take is to set a URL parameter called retURL.  This parameter sets the page that is returned after a save operation.  If you go to an edit page from a list view you will see an example of a URL with the retURL parameter.  Then all you would have to is create custom buttons/links that call your VF page as a URL with the appropiate parameter.  An example URL with the retURL parameter may be as follows:

 

http://na3.salesforce.com/myRecordID/e?retURL=%2fmyDashboardTabRelativeURL

 

Just wanted to give you another option if it will work in your case.

AnnaTAnnaT

Thank you for your replies.

 

I created the following code but error never disappears when I try to deploy it to server...

 

 

public with sharing class SaveController {
      private final CR_CO__c crcopage;
        
    public SaveController(ApexPages.StandardController stdController) {
        this.crcopage=(CR_CO__c)stdController.getRecord();
    }        
     public PageReference saveApp() {
         
            try{
                   insert(crcopage);                                                
             }catch(System.DMLException e){
                ApexPages.addMessages(e);
                 return null;
        }  

                 PageReference p = Page.statuslist;
                  p.setRedirect(true);
                  return p;                              
     } 

}

 I also don't know what to write test code exactly.

My test code is this.

 

private class SaveControllerTest {

    static testMethod void SaveControllerTest() {
        SaveController savecon = new SaveController();
		CR_CO__c ccp = new CR_CO__c();
		
		insert(ccp); 
		
    }
}

 Finally the error message is this.

Method Name Not Available

Line -1, column -1: Dependent class is invalid and needs recompilation:

 

I want to go to same page as save button located.

= I don't want to jump another page after clicking save button.

 

Thanks,

Anna

 

 

AnnaTAnnaT

I changed code as following and I could save it to server.

 

 

public with sharing class SaveController {
    
     public PageReference saveApp() {
         PageReference nextPageURL = new PageReference('/apex/Statuslist');
        
        return nextPageURL;                         
     } 

}

 

 

But at Visualforce page, the followinig error appears when I use this code.

 

<apex:page standardStylesheets="true" showHeader="True" sidebar="false" standardController="CR_CO__c" extensions="SaveController"  recordSetVar="slcrco"  tabstyle="CR_CO__c"> 

 Error: Unknown constructor 'SaveController.SaveController(ApexPages.StandardSetController controller)'

 

 

How can I solve this?

Jake GmerekJake Gmerek

You need a constructor for the extension class.  In your original code, this was your constructor:

 

 

public SaveController(ApexPages.StandardController stdController) {
        this.crcopage=(CR_CO__c)stdController.getRecord();
    }

 

If you re-insert it into your code, that error should go away.

 

AnnaTAnnaT

Thank you for your reply.

 

I inserted the code, but another error appears.

 

public with sharing class SaveController {
    private final CR_CO__c crcopage;
    public SaveController(ApexPages.StandardController stdController) {
        this.crcopage=(CR_CO__c)stdController.getRecord();
    }
     public PageReference saveApp() {
         PageReference nextPageURL = new PageReference('/apex/Statuslist');
        
        return nextPageURL;                         
     } 

}

 line -1, column -1:Dependent class is invalid and needs recompilation:

 


 

Shashikant SharmaShashikant Sharma

Add this to your class

 

 

//constructor
public SaveController(ApexPages.StandardSetController controller) {

} 

 

Save the class, then after saving class now save your page