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
ITENG.SUMANITENG.SUMAN 

save function not working

public class lop {

    public lop(ApexPages.StandardController controller) {

    }
public PageReference save() {
return null;
}

public PageReference saveAndNew() {
PageReference new2= new PageReference('/apex/new2');
new2.setRedirect(true);
return new2;
}
}

can anyone help me figure out what is wrong with my save and new button. The functionality is not working properly, it is not saving, just going to a new page
Best Answer chosen by ITENG.SUMAN
Andy BoettcherAndy Boettcher
You need to create a class variable that holds that controller:
 
public class lop {

    public ApexPages.standardController scMain {get;set;}

    public lop(ApexPages.StandardController controller) {
         scMain = controller;
    }
public PageReference save() {
return null;
}

public PageReference saveAndNew() {
scMain.save();
PageReference new2= new PageReference('/apex/new2');
new2.setRedirect(true);
return new2;
}
}

 

All Answers

Andy BoettcherAndy Boettcher
"SaveAndNew" is not a supported standardController method - to make this work you need to call the controller.save() method in your "saveandnew" method to get that to fire.
ITENG.SUMANITENG.SUMAN
Hey, Thank you. Can you please explain in more detailed way?
Andy BoettcherAndy Boettcher
public class lop {

    public lop(ApexPages.StandardController controller) {

    }
public PageReference save() {
return null;
}

public PageReference saveAndNew() {
controller.save();
PageReference new2= new PageReference('/apex/new2');
new2.setRedirect(true);
return new2;
}
}
ITENG.SUMANITENG.SUMAN
01 public class lop {

02  

03     public lop(ApexPages.StandardController controller) {

04  

05     }

06 public PageReference save() {

07 return null;

08 }

09  

10 public PageReference saveAndNew() {

11 controller.save();

12 PageReference new2= new PageReference('/apex/new2');

13 new2.setRedirect(true);

14 return new2;

15 }

16 }



Still I got error in controoler.save(); method, Like it is shoeing compiler error:Variable does not exist: controller at line 11 column 1
Andy BoettcherAndy Boettcher
You need to create a class variable that holds that controller:
 
public class lop {

    public ApexPages.standardController scMain {get;set;}

    public lop(ApexPages.StandardController controller) {
         scMain = controller;
    }
public PageReference save() {
return null;
}

public PageReference saveAndNew() {
scMain.save();
PageReference new2= new PageReference('/apex/new2');
new2.setRedirect(true);
return new2;
}
}

 
This was selected as the best answer
ITENG.SUMANITENG.SUMAN
thank you so much. It worked :)