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
Giddamreddi ReddyGiddamreddi Reddy 

build custom controller page

Hi 
i am new salesforce learner ,any one help me ... i got this error  when developing controller page on account obj
.
System.NullPointerException: Attempt to de-reference a null object
Error is in expression '{!save}' in component <apex:commandButton> in page customcontroller: Class.custom.save: line 12, column 1
Class.custom.save: line 12, column 1

see bllow  my code.

<apex:page sidebar="false" showheader="false" controller="custom" tabstyle="Account">
 <apex:form > 
 <apex:pageBlock title="Account Information " >
    <apex:pageBlockSection columns="1">
       <apex:inputField value="{!Account.Name}"/>
      <apex:inputField value="{!Account.Phone}"/>
      <apex:inputField value="{!Account.Industry}"/>
     </apex:pageBlockSection>     
      <apex:pageblockButtons >
       <Apex:commandButton value=" save" action="{!save}"/>
      </apex:pageBlockButtons>
   </apex:pageBlock>
 </apex:form>
</apex:page>


apex class
public class custom{
    
    public Account account{get;set;}
     public custom()
     {  
       
    }

    
   public pageReference save(){
   try{
   insert(account); 
   }
   catch(System.DMLException e)
   {
   ApexPages.AddMessages(e);
   return null;
   }
  
   PageReference  pr=new  ApexPages.standardController(account).view();
   return(pr); 
   }
                       
}

give me best solution for this ossue
Amit Chaudhary 8Amit Chaudhary 8
Please try below code. I hope that will help u
public class custom{
    
    public Account account{get;set;}
     public custom()
     {  
		account = new Account();	
     }

    
   public pageReference save(){
   try{
	insert(account); 
   }
   catch(System.DMLException e)
   {
   ApexPages.AddMessages(e);
   return null;
   }
  
   PageReference  pr=new  ApexPages.standardController(account).view();
   return(pr); 
   }
                       
}
Please let us know if this will help you

Thanks
Amit Chaudhary