I am new to salesforce. I was trying to update that account record name belong to me. I am getting

System.NullPointerException: Attempt to de-reference a null object

could some can help me here is my class

public with sharing class AccountController {
    ApexPages.StandardController GstdController;
    public Account ER;

    ApexPages.StandardController stdcontroller;

    public AccountController(ApexPages.StandardController controller) {
       this.ER= (Account)controller.getRecord();
       this.stdController = controller;


    public PageReference Save() {
        String rType = ApexPages.currentPage().getParameters().get('RecordType');
        this.ER.RecordTypeId = rType;

        PageReference pr= stdController.save();
        //insert ER;

        return pr;  
  • Do you know which line is causing the error - the debug log should tell you. I am wondering if the String rType = ApexPages.currentPage().getParameters().get('RecordType'); is throwing an error? Commented Oct 20, 2014 at 4:34
  • iam getting on pr.setRedirect (false); line
    – sravya
    Commented Oct 20, 2014 at 4:42
  • 2
    Seems like there is an error on safe and thus it is returning a null page reference. Check for Page Message to see what the issue is
    – Eric
    Commented Oct 20, 2014 at 5:26
  • 1
    I'm with Eric - execute the save with a try/catch, and then redirect if the save is successful. Commented Oct 20, 2014 at 15:29

1 Answer 1


Based on my understanding, whenever you use getRecord() method, it does not mean it will load all the Account property except if the properties are defined in Visual Force Page example {!RecordTypeId} .

Can you try retrieve Account record including RecordTypeId then update it with the one that you retrieve from parameter?

Something like this:

this.ER =[Select Id,RecordTypeId from Account where Id =: controller.getId()]
this.ER.RecordTypeId = recType;//get this from parameter

//then update code

Hope it help.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .