+ Start a Discussion
Jim MontgomeryJim Montgomery 

System.DmlException: Insert failed. Deployment to production

Getting this error

System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, PfxTaxUpdateOppProposal: execution of AfterUpdate caused by: System.NullPointerException: Attempt to de-reference a null object Trigger.PfxTaxUpdateOppProposal: line 6, column 1: [] 
Stack Trace: Class.TestAxcessInsertTaxUpdateOpps.InsertOpp: line 20, column 1


On this test class

@isTest
Private Class TestPfxInsertTaxUpdateOpps{
static testMethod void InsertOpp(){

TaxUpdateYear__C TUY = new TaxUpdateYear__c(
name = 'UpdateYear',
year__c = '2018');
insert TUY;


Account A = new Account(
            Name = 'myAcct', 
            BillingStreet='25 Upland Drive',
            BillingPostalCode='94127',
            BillingCountry='United States',
            BillingCity='San Francisco',
            Pfx_Tax_Update_Counter__c = 0 );
        insert A;
        
        Account_x_reference__c xref = new account_x_reference__c(
name = '990026',
applicationid__c = '990026', 
application__c = 'AMS', ams_special_agreement__c = 'X', ams_consolidation_code__c = '028',
account__c = a.id);
insert xref;
        
        A.Pfx_Tax_Update_Counter__C = 1;
        a.Tax_Update_Account_Number__c = xref.id;
        
        update a;
        
        
   
        }
        }  

on this trigger

2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
trigger AxcessTaxUpdateOppProposal on Account (after update) {
    for (Account A:trigger.new){
    TaxUpdateYear__C TUY = TaxUpdateYear__c.getInstance('UpdateYear');
    String Year = TUY.year__c;
           Account oldAccount = Trigger.oldMap.get(A.Id);
        if(oldAccount.Axcess_Tax_Update_Counter__C <>  A.Axcess_Tax_Update_Counter__C){
          Opportunity O = new Opportunity(
          accountId = A.Id,
          name = a.name +' - '+Year+' Tax Update Order',
          amount = 150.00,
          StageName = '5. Time to Buy',
          ForecastCategoryName = 'High Probability',
          Forecast_Type__c = 'High(>90%)',
          Primary_contact_for_proposal__c = a.tax_update_contact__c,
          primary_contact_email__c = a.tax_update_contact_email__c,
          primary_contact_phone__C = a.tax_Update_Contact_phone__c,
          product_category__c = 'Small Firm Software',
          product_sub_category__c = 'Tax',
          type = 'New to Existing',
          RecordTypeId = '01231000001NWytAAG',
          closedate = system.Today(),
          OwnerId = UserInfo.getUserId()); 
          insert O;
            
            apttus_proposal__proposal__c P = new apttus_proposal__proposal__c(
            apttus_proposal__account__c = A.Id,
            apttus_proposal__proposal_name__c = O.name,
            apttus_proposal__approval_stage__c = 'Approved',
            apttus_proposal__opportunity__c = O.Id,
            quote_total__C = 150.00,
            RecordTypeId = '012i0000001EOtSAAW',
            apttus_QPConfig__PriceListId__c = 'a1fi0000000y6L4AAI',
            OwnerId = UserInfo.getUserId(),
            annual_start_date__c = system.Today()
          ,erp_account__c = A.Tax_Update_Account_number__c );            
            insert P;
            
            apttus_Config2__ProductConfiguration__c C = new apttus_Config2__ProductConfiguration__c (
            name = p.name,
            ownerId = UserInfo.getUserId(),
            Apttus_Config2__BusinessObjectId__c = P.Id,
            Apttus_Config2__BusinessObjectType__c = 'Proposal',
            Apttus_Config2__EffectivePriceListId__c = 'a1fi0000000y6L4AAI',
            Apttus_Config2__PriceListId__c = 'a1fi0000000y6L4AAI',
            Apttus_QPConfig__Proposald__c = P.Id,
            Apttus_Config2__Status__C = 'Finalized',
            Apttus_Config2__VersionNumber__c = 1,
            Proposal_ID__c = P.Id);
            Insert C;
            
             Apttus_Config2__LineItem__c CLI = new Apttus_Config2__LineItem__c(
                Apttus_Config2__ConfigurationId__c = C.Id,
                Apttus_Config2__ChargeType__c = 'One Time Fee',
                Apttus_Config2__BasePrice__c = 150.00,
                Apttus_Config2__BaseExtendedPrice__c = 150.00,
                Apttus_Config2__ExtendedPrice__c = 150.00,
                Apttus_Config2__IsPrimaryLine__c = true,
                Apttus_Config2__ItemSequence__c = 1,
                Apttus_Config2__LineNumber__c = 1,
                Apttus_Config2__ListPrice__c = 150.00,
                Apttus_Config2__LineStatus__c = 'New',
                Apttus_Config2__NetPrice__c = 150.00,
                Apttus_Config2__PriceListId__c = 'a1fi0000000y6L4AAI',
                apttus_config2__PriceListItemId__c = 'a1e0S0000007RYK',
                Apttus_Config2__PriceType__c = 'One Time',
                Apttus_Config2__ProductId__c = '01t0S000000krh9',
                Apttus_Config2__Quantity__c = 1,
                Apttus_Config2__SellingFrequency__c = 'Yearly',
                Apttus_Config2__SyncStatus__c = 'Synchronized',
                Apttus_Config2__PricingStatus__c = 'Complete',
                Apttus_Config2__PrimaryLineNumber__c = 1);
                Insert CLI; 
            
             
              apttus_proposal__proposal_line_item__c PLI = new apttus_proposal__proposal_line_item__c(
              apttus_proposal__proposal__c = p.Id,
                apttus_proposal__product__c = '01t0S000000krh9',
                apttus_qpconfig__quantity2__c = 1,
                apttus_qpconfig__linenumber__c = 1,
                apttus_qpconfig__itemsequence__c = 1,
                apttus_qpconfig__listprice__c = 150.00000,
                apttus_qpconfig__netprice__c = 150.00,
                apttus_qpconfig__linestatus__c = 'New',
                apttus_qpconfig__lineType__c = 'Product/Service',
                apttus_proposal__description__c = 'CCH AXCESS TAX UPDATE SEMINAR - MTS',
                apttus_qpconfig__PriceListItemId__c = 'a1e0S0000007RYK');
                insert PLI;
             Template_Line_item__C TLI = new Template_Line_Item__C(
                OwnerId = UserInfo.getUserId(),
                name = 'QLI-Record',
                ams_product_Category__c = 'Tax Professional & Client Services',
                Product__c = '01t0S000000krh9',
                Quote_Proposal__C = p.Id,
                display_ams_product_category__c = 'Tax Professional & Client Services',
                proposal_line_item__C = PLI.Id);
                
                insert TLI;
                
                  P.quote_total__c = 150.00;
                Update P;
                
                opportunitylineitem OLI = new opportunitylineitem(
                opportunityId = O.Id,
                product2Id = '01t0S000000krh9',
                Quantity = 1,
                TotalPrice = 150.00,
                Item_Number__C = '1',
                BasePrice__c = 150.00,
                PriceBookEntryId = '01u0S000001Lr93');
            
                
                insert OLI;   
               
                
   }
}
}


Trigger has 100% coverage in test.
Not sure why it is failing during deployment.
 
v varaprasadv varaprasad
Hi Jim,

In trigger please remove hardcode ids and follow best practices.

More Info : Please check once below link : 
https://developer.salesforce.com/forums/?id=906F0000000DBl8IAG

Please use all fields test class whatever using the in trigger.to avoid null pointer exeption.


Thanks
Varaprasad
 
James LoghryJames Loghry
It looks like your exception is caused by the field "Axcess_Tax_Update_Counter__c" being null.  You'll want to do a few things.  First, make sure you're setting Axcess_Tax_Update_Counter__c to 0 (or some other non null value) in your test class. Second, add some null checking in your trigger.

For instance, try updating this line:
if(oldAccount.Axcess_Tax_Update_Counter__C <>  A.Axcess_Tax_Update_Counter__C)

To:
 
if(oldAccount.Axcess_Tax_Update_Counter__c != null &&   a.Axcess_Tax_Update_Counter__C != null && oldAccount.Axcess_Tax_Update_Counter__C <>  A.Axcess_Tax_Update_Counter__C)

 
Amit Chaudhary 8Amit Chaudhary 8
Hi,
Issue is coming in your test class "TestAxcessInsertTaxUpdateOpps".

Makre sure add value for Axcess_Tax_Update_Counter__c field.
Or update your trigger like below

trigger AxcessTaxUpdateOppProposal on Account (after update) {
    for (Account A:trigger.new){
    TaxUpdateYear__C TUY = TaxUpdateYear__c.getInstance('UpdateYear');
    String Year = TUY.year__c;
           Account oldAccount = Trigger.oldMap.get(A.Id);
        if( a.Axcess_Tax_Update_Counter__C!= null && oldAccount.Axcess_Tax_Update_Counter__c != null && oldAccount.Axcess_Tax_Update_Counter__C !=  A.Axcess_Tax_Update_Counter__C){
          Opportunity O = new Opportunity(
          accountId = A.Id,
          name = a.name +' - '+Year+' Tax Update Order',
          amount = 150.00,
          StageName = '5. Time to Buy',
          ForecastCategoryName = 'High Probability',
          Forecast_Type__c = 'High(>90%)',
          Primary_contact_for_proposal__c = a.tax_update_contact__c,
          primary_contact_email__c = a.tax_update_contact_email__c,
          primary_contact_phone__C = a.tax_Update_Contact_phone__c,
          product_category__c = 'Small Firm Software',
          product_sub_category__c = 'Tax',
          type = 'New to Existing',
          RecordTypeId = '01231000001NWytAAG',
          closedate = system.Today(),
          OwnerId = UserInfo.getUserId());
          insert O;
            
            apttus_proposal__proposal__c P = new apttus_proposal__proposal__c(
            apttus_proposal__account__c = A.Id,
            apttus_proposal__proposal_name__c = O.name,
            apttus_proposal__approval_stage__c = 'Approved',
            apttus_proposal__opportunity__c = O.Id,
            quote_total__C = 150.00,
            RecordTypeId = '012i0000001EOtSAAW',
            apttus_QPConfig__PriceListId__c = 'a1fi0000000y6L4AAI',
            OwnerId = UserInfo.getUserId(),
            annual_start_date__c = system.Today()
          ,erp_account__c = A.Tax_Update_Account_number__c );            
            insert P;
            
            apttus_Config2__ProductConfiguration__c C = new apttus_Config2__ProductConfiguration__c (
            name = p.name,
            ownerId = UserInfo.getUserId(),
            Apttus_Config2__BusinessObjectId__c = P.Id,
            Apttus_Config2__BusinessObjectType__c = 'Proposal',
            Apttus_Config2__EffectivePriceListId__c = 'a1fi0000000y6L4AAI',
            Apttus_Config2__PriceListId__c = 'a1fi0000000y6L4AAI',
            Apttus_QPConfig__Proposald__c = P.Id,
            Apttus_Config2__Status__C = 'Finalized',
            Apttus_Config2__VersionNumber__c = 1,
            Proposal_ID__c = P.Id);
            Insert C;
            
             Apttus_Config2__LineItem__c CLI = new Apttus_Config2__LineItem__c(
                Apttus_Config2__ConfigurationId__c = C.Id,
                Apttus_Config2__ChargeType__c = 'One Time Fee',
                Apttus_Config2__BasePrice__c = 150.00,
                Apttus_Config2__BaseExtendedPrice__c = 150.00,
                Apttus_Config2__ExtendedPrice__c = 150.00,
                Apttus_Config2__IsPrimaryLine__c = true,
                Apttus_Config2__ItemSequence__c = 1,
                Apttus_Config2__LineNumber__c = 1,
                Apttus_Config2__ListPrice__c = 150.00,
                Apttus_Config2__LineStatus__c = 'New',
                Apttus_Config2__NetPrice__c = 150.00,
                Apttus_Config2__PriceListId__c = 'a1fi0000000y6L4AAI',
                apttus_config2__PriceListItemId__c = 'a1e0S0000007RYK',
                Apttus_Config2__PriceType__c = 'One Time',
                Apttus_Config2__ProductId__c = '01t0S000000krh9',
                Apttus_Config2__Quantity__c = 1,
                Apttus_Config2__SellingFrequency__c = 'Yearly',
                Apttus_Config2__SyncStatus__c = 'Synchronized',
                Apttus_Config2__PricingStatus__c = 'Complete',
                Apttus_Config2__PrimaryLineNumber__c = 1);
                Insert CLI;
            
             
              apttus_proposal__proposal_line_item__c PLI = new apttus_proposal__proposal_line_item__c(
              apttus_proposal__proposal__c = p.Id,
                apttus_proposal__product__c = '01t0S000000krh9',
                apttus_qpconfig__quantity2__c = 1,
                apttus_qpconfig__linenumber__c = 1,
                apttus_qpconfig__itemsequence__c = 1,
                apttus_qpconfig__listprice__c = 150.00000,
                apttus_qpconfig__netprice__c = 150.00,
                apttus_qpconfig__linestatus__c = 'New',
                apttus_qpconfig__lineType__c = 'Product/Service',
                apttus_proposal__description__c = 'CCH AXCESS TAX UPDATE SEMINAR - MTS',
                apttus_qpconfig__PriceListItemId__c = 'a1e0S0000007RYK');
                insert PLI;
             Template_Line_item__C TLI = new Template_Line_Item__C(
                OwnerId = UserInfo.getUserId(),
                name = 'QLI-Record',
                ams_product_Category__c = 'Tax Professional & Client Services',
                Product__c = '01t0S000000krh9',
                Quote_Proposal__C = p.Id,
                display_ams_product_category__c = 'Tax Professional & Client Services',
                proposal_line_item__C = PLI.Id);
                
                insert TLI;
                
                  P.quote_total__c = 150.00;
                Update P;
                
                opportunitylineitem OLI = new opportunitylineitem(
                opportunityId = O.Id,
                product2Id = '01t0S000000krh9',
                Quantity = 1,
                TotalPrice = 150.00,
                Item_Number__C = '1',
                BasePrice__c = 150.00,
                PriceBookEntryId = '01u0S000001Lr93');
            
                
                insert OLI;   
               
                
   }
}
}

Let us know if this will help you
Jim MontgomeryJim Montgomery
I have set the Axcess_tax_Update_Counter__c = 0 in the test class. I added the null checking as well but still get the same error. Jim Montgomery Manager, Sales Intelligence Operations North America Tax & Accounting 20101 Hamilton Ave. Torrance, CA 90502 877-346-7148 jim.montgomery@wolterskluwer.com [wklogo] Confidentiality Notice: This email and any attachments may contain confidential or privileged information that is intended for the addressee only. If you are not an intended recipient of the original sender (or responsible for delivering the message to such person), you are hereby notified that any review, disclosure, copying, distribution or the taking of any action in reliance of the contents of and attachments to this email is strictly prohibited. If you have received this email in error, please immediately notify the sender at the address shown herein and permanently delete any copies of this email (digital or paper) in your possession. Wolters Kluwer shall not be liable for the incorrect or incomplete transmission of this email or any attachments, nor for unauthorized use by its employees.