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
Prallavi DuaPrallavi 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;
}
karthikeyan perumalkarthikeyan perumal
Hello, 

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