You need to sign in to do that
Don't have an account?
Manvendra Singh Rathore 22
Stop standard validations on custom cancel button in custom controller
I have impletemened account insert page, with custom controller.
Here is the code for custom controller :
public class AccountInsertPageCustomCtrl {
public Account acc{get; set;}
public AccountInsertPageCustomCtrl(){
acc = new Account();
}
public PageReference Save(){
if(acc != null){
insert acc;
}
PageReference pg = new PageReference('/'+acc.Id);
pg.setRedirect(true);
return pg;
}
public PageReference SaveAndNew(){
if(acc != null){
insert acc;
}
PageReference pg = new PageReference('/001/e?retURL=%2F0016F00002CaaO4');
pg.setRedirect(true);
return pg;
}
public PageReference Cancel(){
//PageReference pg = new PageReference('/001/o');
//pg.setRedirect(true);
return null;
}
}
Scenario : when I open the VF Enter the required fields, and without clicking on Save and Save&New button, if I click on Cancel, its working fine. as per I have mentioned in the code. but when I do not enter anything, its showing me validation error for Account name ? how can I make it work? I mean, on clicking on Cancel, it must redirect to the All accounts page.
Here is the code for custom controller :
public class AccountInsertPageCustomCtrl {
public Account acc{get; set;}
public AccountInsertPageCustomCtrl(){
acc = new Account();
}
public PageReference Save(){
if(acc != null){
insert acc;
}
PageReference pg = new PageReference('/'+acc.Id);
pg.setRedirect(true);
return pg;
}
public PageReference SaveAndNew(){
if(acc != null){
insert acc;
}
PageReference pg = new PageReference('/001/e?retURL=%2F0016F00002CaaO4');
pg.setRedirect(true);
return pg;
}
public PageReference Cancel(){
//PageReference pg = new PageReference('/001/o');
//pg.setRedirect(true);
return null;
}
}
Scenario : when I open the VF Enter the required fields, and without clicking on Save and Save&New button, if I click on Cancel, its working fine. as per I have mentioned in the code. but when I do not enter anything, its showing me validation error for Account name ? how can I make it work? I mean, on clicking on Cancel, it must redirect to the All accounts page.
On your VF page, <apex:commandbutton tag use "immediate" attribute, and mark its value to true.
https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_commandButton.htm
Best Regards
Nisar
Happy Coding :)
All Answers
On your VF page, <apex:commandbutton tag use "immediate" attribute, and mark its value to true.
https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_commandButton.htm
Best Regards
Nisar
Happy Coding :)