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
lawlaw 

attempt to de-reference a null object

I am receiving the following error.  I have included the code after the error.  Any help would be appreciated.

 

Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger ContactOpportunityStage caused an unexpected exception, contact your administrator: ContactOpportunityStage: execution of AfterInsert caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.ContactOpportunityStage: line 13, column 1

 

 

 

trigger ContactOpportunityStage on Opportunity (after insert, before update) {
    
    SingletonResource singleton = SingletonResource.getInstance();
    Stage_And_Status__c oppStages = Stage_And_Status__c.getInstance('Opportunity Stages');
    Stage_And_Status__c contactStatuses = Stage_And_Status__c.getInstance('Contact Statuses');
    // Opportunity stages
    Map<String, Integer> oppStageMap = new Map<String, Integer> {   /////LINE 13
        oppStages.Open_Meeting__c => 1,
        oppStages.Closed_Meeting_Withdrew__c => 2,
        oppStages.Closed_Meeting_AMPF_Declined__c => 3,
        oppStages.Open_Due_Diligence__c => 4,
        oppStages.Closed_DD_Withdrew__c => 5,
        oppStages.Closed_DD_Background__c => 6,
        oppStages.Closed_DD_Hiring_Mgr__c => 7,
        oppStages.Closed_DD_Governance__c => 8,
        oppStages.Open_Offer_Extended__c => 9,
        oppStages.Closed_Offer_Declined__c => 10,
        oppStages.Closed_Offer_Expired__c => 11,
        oppStages.Closed_Offer_Accepted__c => 12
        //oppStages.Open_Offer_Generation__c => 3,
       // oppStages.Open_Offer_Accepted__c => 12,
        //oppStages.Closed_Won_Hired__c => 13        
    };

bob_buzzardbob_buzzard

This suggests that oppStages is null - I'd add some debug to dump out the setting once you've retrieved it.

vbsvbs
The only reason I see is 'oppStages' object being nul and not being instantiated correctly in the 3 line in the script. Can you add a system.debug to check the value of oppStages?
lawlaw

yes oppstages is null ...but I am not sure why?

vbsvbs
Have a look at what what Stage_And_Status__c.getInstance('Opportunity Stages') does. It surely returns an instance of Stage_And_Status__c class but there may be a spelling issue with the parameter passed or it not being able to understand the term 'Opportunity Stages'
vbsvbs
On second thoughts this looks like the code trying to get a custom setting. Have you setup a list custom setting with the name 'Opportunity Stages'. If yes, is the name correct?