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
Salesforce Developer MOSalesforce Developer MO 

Issue with test class not running Standardcontroller getRecord()...

Hello all,

 

Im having an issue getting my test class to execute the getRecords() method. The error is a dereference null value on the line where that method is used. How do I get it to recognize the value Im trying to pass into the controller from the test class?

 

@isTest
private class TestSalesConnectContactQuickBuild {

    static testMethod void myUnitTest() {
    	
    	Unmatched_Contact__c contactRecord = new Unmatched_Contact__c(Last_Name__c='TESTDATA',OwnerId=UserInfo.getUserId(),Firm_Internal_ID__c='1');
    	insert contactRecord;
    	
    	Test.startTest();

        ApexPages.Standardcontroller stdCtrl = new ApexPages.Standardcontroller(contactRecord);
        
        SalesConnectContactQuickBuildController controller = new SalesConnectContactQuickBuildController(stdCtrl);
        
        Test.stopTest();
    }
}

 

Here is the controller code...

 

public class SalesConnectContactQuickBuildController {

    ApexPages.StandardController setController;

    public list<Unmatched_Contact__c> unmatchedContactsSelected {get;set;}
    
    public SalesConnectContactQuickBuildController (ApexPages.StandardController controller) {
        setController = controller;
        unmatchedContactsSelected = new list<Unmatched_Contact__c>(); 
        //****ERROR OCCURS ON LINE BELOW - DEREFERENCE NULL VALUE*** 
	unmatchedContactsSelected.add((Unmatched_Contact__c)setCon.getRecord());
        init();
    }
	...
}

 

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

Is this really the controller code?  The reason I ask is I wouldn't expect it to compile, as you have no poperty named 'setCon' which you try to use in the line which is erroring:

 

unmatchedContactsSelected.add((Unmatched_Contact__c)setCon.getRecord());

 

If you have an additional property named 'setCon', that would explain the error as you are assigning the standard controller to a property named 'setController'.

All Answers

bob_buzzardbob_buzzard

Is this really the controller code?  The reason I ask is I wouldn't expect it to compile, as you have no poperty named 'setCon' which you try to use in the line which is erroring:

 

unmatchedContactsSelected.add((Unmatched_Contact__c)setCon.getRecord());

 

If you have an additional property named 'setCon', that would explain the error as you are assigning the standard controller to a property named 'setController'.

This was selected as the best answer
Salesforce Developer MOSalesforce Developer MO

Can't believe I missed that. Thank you for your help!