You need to sign in to do that
Don't have an account?
Prallavi Dua
PageReference prf = null;
Hi,
Below is code which I got from blog, in that code can anyone explain me Why
PageReference prf = null; is written.
Why it can not be written as PageReference prf = new Pagereference();
in saverec(),
public class ActionFunctionCLS {
public Account actObj{get;set;}
PageReference prf= null;
public ActionFunctionCLS(){
actObj = new Account();
}
public pagereference Saverec(){
if(actobj.Name !=''){
insert actobj;
}
else{
ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'Error: Please Enter Name.');
ApexPages.addMessage(myMsg);
}
return prf;
}
}
Below is code which I got from blog, in that code can anyone explain me Why
PageReference prf = null; is written.
Why it can not be written as PageReference prf = new Pagereference();
in saverec(),
public class ActionFunctionCLS {
public Account actObj{get;set;}
PageReference prf= null;
public ActionFunctionCLS(){
actObj = new Account();
}
public pagereference Saverec(){
if(actobj.Name !=''){
insert actobj;
}
else{
ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'Error: Please Enter Name.');
ApexPages.addMessage(myMsg);
}
return prf;
}
}
you are just Creating instance for your pagereference without having garbage value for that instance i.e "prf". but actually you are not Instantiation the pagereference. when ever you want to Instantiation of this page you have to do the another line code like below
prf= new PageReference();
Hope this will help you,
Mark Best ANSWER if its clear.
Thanks
karthik