You need to sign in to do that
Don't have an account?
JN22
Error When Trying to Deploy to Production
Hello,
I am trying to deploy a trigger (UniqueDelivID) from my sandbox to production. The trigger works fine in my sandbox and is covered 100% by the test class. Yet when I try to move to production, I get the error below:
System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, OppUpdates: execution of AfterInsert caused by: System.DmlException: Update failed. First exception on row 0 with id 00k7000000U8CVpAAN; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, UniqueDelivID: execution of BeforeUpdate caused by: System.NullPointerException: Attempt to de-reference a null object Trigger.UniqueDelivID: line 22, column 1: [] Trigger.OppUpdates: line 49, column 1: []
Stack Trace: Class.TestOppUpdates.TestOppUpdates: line 379, column 1
Does anyone know why I am getting this error? Thanks.
Trigger (UniqueDelivID)
Test Class (TestOppUpdates)
I am trying to deploy a trigger (UniqueDelivID) from my sandbox to production. The trigger works fine in my sandbox and is covered 100% by the test class. Yet when I try to move to production, I get the error below:
System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, OppUpdates: execution of AfterInsert caused by: System.DmlException: Update failed. First exception on row 0 with id 00k7000000U8CVpAAN; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, UniqueDelivID: execution of BeforeUpdate caused by: System.NullPointerException: Attempt to de-reference a null object Trigger.UniqueDelivID: line 22, column 1: [] Trigger.OppUpdates: line 49, column 1: []
Stack Trace: Class.TestOppUpdates.TestOppUpdates: line 379, column 1
Does anyone know why I am getting this error? Thanks.
Trigger (UniqueDelivID)
//Assigns a unique ID to each deliverable in every Opportunity so DyNad can track. trigger UniqueDelivID on OpportunityLineItem (before insert, before update) { //if(checkRecursiveBI.runOnceBI()||checkRecursiveBU.runOnceBU()) //{ Set<ID> setOliIds = new Set<ID>(); for(OpportunityLineItem oli:Trigger.new){ setOliIds.add(oli.Id); } Map<ID, OpportunityLineItem> mapOli = new Map<ID, OpportunityLineItem>([SELECT Id, Opportunity.Max_Deliv_Hx__c, Max_Deliv__c FROM OpportunityLineItem WHERE Id in:setOliIds]); if(mapOli.size()>0){ /* List<OpportunityLineItem> oli1 = [SELECT Id, Max_Deliv__c FROM OpportunityLineItem WHERE Id IN: Trigger.newMap.keySet()]; for (OpportunityLineItem oli :oli1){*/ for(OpportunityLineItem oli1:Trigger.New){ IF(mapOli.containsKey(oli1.Id) && (oli1.Max_Deliv__c == 0 || oli1.Max_Deliv__c == null)){ oli1.Max_Deliv__c = mapOli.get(oli1.Id).Opportunity.Max_Deliv_Hx__c + 1; } } } //} }
Test Class (TestOppUpdates)
// This class tests the trigger named OppUpdates. @isTest(seeAllData=true) public class TestOppUpdates { public static testMethod void TestOppUpdates() { //Data Prep - Create Account, Opportunity, Product, etc. Account acct = TestCreateRecords.createAcct(0); insert acct; //Create Opportunity on Account Opportunity Opp = TestCreateRecords.createOpp(acct.Id); insert Opp; // Create Deliverables List<product2> Insertprodlist= new list<product2>(); //High-Risk Coaching Product2 deliv1 = new Product2 (name='Coaching-HR'); deliv1.ProductCode = 'COACH_HR'; deliv1.Product_Group__c = 'Coaching'; Insertprodlist.add(deliv1); //Moderate-Risk Coaching Product2 deliv2 = new Product2 (name='Coaching-MR'); deliv2.productcode = 'COACH_MR'; deliv2.Product_Group__c = 'Coaching'; Insertprodlist.add(deliv2); //Low-Risk Coaching Product2 deliv3 = new Product2 (name='Coaching-LR'); deliv3.productcode = 'COACH_LR'; deliv3.Product_Group__c = 'Coaching'; Insertprodlist.add(deliv3); //Other Coaching Product2 deliv4 = new Product2 (name='Coaching-OTHER'); deliv4.productcode = 'COACH_SELFREF'; deliv4.Product_Group__c = 'Coaching'; Insertprodlist.add(deliv4); //Weight Management Product2 deliv5 = new Product2 (name='Weight Management'); deliv5.productcode = 'WEIGHTMGMTNODEVICE'; deliv5.Product_Group__c = 'Weight Management'; Insertprodlist.add(deliv5); //Tobacco Cessation Product2 deliv6 = new Product2 (name='Tobacco'); deliv6.productcode = 'TOB_COACH'; deliv6.Product_Group__c = 'Tobacco Cessation'; Insertprodlist.add(deliv6); //Condition Management - Diabetes Product2 deliv7 = new Product2 (name='CM-Diabetes'); deliv7.productcode = 'DIAB_COACH'; deliv7.Product_Group__c = 'Condition Management'; Insertprodlist.add(deliv7); //Condition Management - CHF Product2 deliv8 = new Product2 (name='CM-CHF'); deliv8.productcode = 'HF_COACH'; deliv8.Product_Group__c = 'Condition Management'; Insertprodlist.add(deliv8); //Condition Management - CAD Product2 deliv9 = new Product2 (name='CM-CAD'); deliv9.productcode = 'CAD_COACH'; deliv9.Product_Group__c = 'Condition Management'; Insertprodlist.add(deliv9); //Condition Management - COPD Product2 deliv10 = new Product2 (name='CM-COPD'); deliv10.productcode = 'COPD_COACH'; deliv10.Product_Group__c = 'Condition Management'; Insertprodlist.add(deliv10); //Condition Management - Asthma Product2 deliv11 = new Product2 (name='CM-Asthma'); deliv11.productcode = 'ASTH_COND_COACH'; deliv11.Product_Group__c = 'Condition Management'; Insertprodlist.add(deliv11); //Condition Management - Telephonic Bundle Product2 deliv12 = new Product2 (name='CM-Tel Bundle'); deliv12.productcode = 'CMBUNDLE'; deliv12.Product_Group__c = 'Condition Management'; Insertprodlist.add(deliv12); //Health Concierge Product2 deliv13 = new Product2 (name='Health Concierge'); deliv13.productcode = 'HCPLC_CGS'; deliv13.Product_Group__c = 'Health Concierge'; Insertprodlist.add(deliv13); //OWC Product2 deliv14 = new Product2 (name='Onsite Wellness Coordinators'); deliv14.productcode = 'WELL_COORD'; deliv14.Product_Group__c = 'Onsite Wellness Coordinators'; Insertprodlist.add(deliv14); //Platform Product2 deliv15 = new Product2 (name='Core Package'); deliv15.productcode = 'CORE_PKG'; deliv15.Product_Group__c = 'Platform'; Insertprodlist.add(deliv15); //Biometrics Product2 deliv16 = new Product2 (name='Biometrics'); deliv16.productcode = 'BIOMETRIC_ONSITE'; deliv16.Product_Group__c = 'Biometrics'; Insertprodlist.add(deliv16); //Diabetes Product2 deliv17 = new Product2 (name='Diabetes'); deliv17.productcode = 'DIAB_COACH'; deliv17.Product_Group__c = 'Diabetes'; Insertprodlist.add(deliv17); //Wellness Challenges Product2 deliv18 = new Product2 (name='Wellness Challenges'); deliv18.productcode = 'WELLNESS'; deliv18.Product_Group__c = 'Wellness Challenge'; Insertprodlist.add(deliv18); //International - Platform /* Product2 deliv19 = new Product2 (name='International-Platform'); deliv19.productcode = 'INT_PLAT'; deliv19.Product_Group__c = 'International - Platform'; Insertprodlist.add(deliv19); //International - Coaching Product2 deliv20 = new Product2 (name='International-Coaching'); deliv20.productcode = 'INT_COACH'; deliv20.Product_Group__c = 'International - Coaching'; Insertprodlist.add(deliv20);*/ insert Insertprodlist; // Get Pricebook Pricebook2 testpb = [select id from Pricebook2 where IsStandard = true]; List<PricebookEntry> InsertPricebookList= new List<PricebookEntry>(); // Add to pricebook PricebookEntry testdeliv1 = new PricebookEntry (); testdeliv1.pricebook2id = testpb.id; testdeliv1.product2id = deliv1.id; testdeliv1.IsActive = True; testdeliv1.UnitPrice = 10000; testdeliv1.UseStandardPrice = false; InsertPricebookList.add(testdeliv1); PricebookEntry testdeliv2 = new PricebookEntry (); testdeliv2.pricebook2id = testpb.id; testdeliv2.product2id = deliv2.id; testdeliv2.IsActive = True; testdeliv2.UnitPrice = 10000; testdeliv2.UseStandardPrice = false; InsertPricebookList.add(testdeliv2); PricebookEntry testdeliv3 = new PricebookEntry (); testdeliv3.pricebook2id = testpb.id; testdeliv3.product2id = deliv3.id; testdeliv3.IsActive = True; testdeliv3.UnitPrice = 10000; testdeliv3.UseStandardPrice = false; InsertPricebookList.add(testdeliv3); PricebookEntry testdeliv4 = new PricebookEntry (); testdeliv4.pricebook2id = testpb.id; testdeliv4.product2id = deliv4.id; testdeliv4.IsActive = True; testdeliv4.UnitPrice = 10000; testdeliv4.UseStandardPrice = false; InsertPricebookList.add(testdeliv4); PricebookEntry testdeliv5 = new PricebookEntry (); testdeliv5.pricebook2id = testpb.id; testdeliv5.product2id = deliv5.id; testdeliv5.IsActive = True; testdeliv5.UnitPrice = 10000; testdeliv5.UseStandardPrice = false; InsertPricebookList.add(testdeliv5); PricebookEntry testdeliv6 = new PricebookEntry (); testdeliv6.pricebook2id = testpb.id; testdeliv6.product2id = deliv6.id; testdeliv6.IsActive = True; testdeliv6.UnitPrice = 10000; testdeliv6.UseStandardPrice = false; InsertPricebookList.add(testdeliv6); PricebookEntry testdeliv7 = new PricebookEntry (); testdeliv7.pricebook2id = testpb.id; testdeliv7.product2id = deliv7.id; testdeliv7.IsActive = True; testdeliv7.UnitPrice = 10000; testdeliv7.UseStandardPrice = false; InsertPricebookList.add(testdeliv7); PricebookEntry testdeliv8 = new PricebookEntry (); testdeliv8.pricebook2id = testpb.id; testdeliv8.product2id = deliv8.id; testdeliv8.IsActive = True; testdeliv8.UnitPrice = 10000; testdeliv8.UseStandardPrice = false; InsertPricebookList.add(testdeliv8); PricebookEntry testdeliv9 = new PricebookEntry (); testdeliv9.pricebook2id = testpb.id; testdeliv9.product2id = deliv9.id; testdeliv9.IsActive = True; testdeliv9.UnitPrice = 10000; testdeliv9.UseStandardPrice = false; InsertPricebookList.add(testdeliv9); PricebookEntry testdeliv10 = new PricebookEntry (); testdeliv10.pricebook2id = testpb.id; testdeliv10.product2id = deliv10.id; testdeliv10.IsActive = True; testdeliv10.UnitPrice = 10000; testdeliv10.UseStandardPrice = false; InsertPricebookList.add(testdeliv10); PricebookEntry testdeliv11 = new PricebookEntry (); testdeliv11.pricebook2id = testpb.id; testdeliv11.product2id = deliv11.id; testdeliv11.IsActive = True; testdeliv11.UnitPrice = 10000; testdeliv11.UseStandardPrice = false; InsertPricebookList.add(testdeliv11); PricebookEntry testdeliv12 = new PricebookEntry (); testdeliv12.pricebook2id = testpb.id; testdeliv12.product2id = deliv12.id; testdeliv12.IsActive = True; testdeliv12.UnitPrice = 10000; testdeliv12.UseStandardPrice = false; InsertPricebookList.add(testdeliv12); PricebookEntry testdeliv13 = new PricebookEntry (); testdeliv13.pricebook2id = testpb.id; testdeliv13.product2id = deliv13.id; testdeliv13.IsActive = True; testdeliv13.UnitPrice = 10000; testdeliv13.UseStandardPrice = false; InsertPricebookList.add(testdeliv13); PricebookEntry testdeliv14 = new PricebookEntry (); testdeliv14.pricebook2id = testpb.id; testdeliv14.product2id = deliv14.id; testdeliv14.IsActive = True; testdeliv14.UnitPrice = 10000; testdeliv14.UseStandardPrice = false; InsertPricebookList.add(testdeliv14); PricebookEntry testdeliv15 = new PricebookEntry (); testdeliv15.pricebook2id = testpb.id; testdeliv15.product2id = deliv15.id; testdeliv15.IsActive = True; testdeliv15.UnitPrice = 10000; testdeliv15.UseStandardPrice = false; InsertPricebookList.add(testdeliv15); PricebookEntry testdeliv16 = new PricebookEntry (); testdeliv16.pricebook2id = testpb.id; testdeliv16.product2id = deliv16.id; testdeliv16.IsActive = True; testdeliv16.UnitPrice = 10000; testdeliv16.UseStandardPrice = false; InsertPricebookList.add(testdeliv16); PricebookEntry testdeliv17 = new PricebookEntry (); testdeliv17.pricebook2id = testpb.id; testdeliv17.product2id = deliv17.id; testdeliv17.IsActive = True; testdeliv17.UnitPrice = 10000; testdeliv17.UseStandardPrice = false; InsertPricebookList.add(testdeliv17); PricebookEntry testdeliv18 = new PricebookEntry (); testdeliv18.pricebook2id = testpb.id; testdeliv18.product2id = deliv18.id; testdeliv18.IsActive = True; testdeliv18.UnitPrice = 10000; testdeliv18.UseStandardPrice = false; InsertPricebookList.add(testdeliv18); /* PricebookEntry testdeliv19 = new PricebookEntry (); testdeliv19.pricebook2id = testpb.id; testdeliv19.product2id = deliv19.id; testdeliv19.IsActive = True; testdeliv19.UnitPrice = 10000; testdeliv19.UseStandardPrice = false; InsertPricebookList.add(testdeliv19); PricebookEntry testdeliv20 = new PricebookEntry (); testdeliv20.pricebook2id = testpb.id; testdeliv20.product2id = deliv20.id; testdeliv20.IsActive = True; testdeliv20.UnitPrice = 10000; testdeliv20.UseStandardPrice = false; InsertPricebookList.add(testdeliv20);*/ Insert InsertPricebookList; test.starttest(); List<OpportunityLineItem> oli1 = new List<OpportunityLineItem>(); integer todo = 20; for(integer bi=0; bi<todo; bi++) { oli1.add( new OpportunityLineItem(Quantity = 1, TotalPrice = 10000, PriceBookEntryId = testdeliv1.id, OpportunityId = Opp.id) ); oli1.add( new OpportunityLineItem(Quantity = 1, TotalPrice = 10000, PriceBookEntryId = testdeliv2.id, OpportunityId = Opp.id) ); oli1.add( new OpportunityLineItem(Quantity = 1, TotalPrice = 10000, PriceBookEntryId = testdeliv3.id, OpportunityId = Opp.id) ); oli1.add( new OpportunityLineItem(Quantity = 1, TotalPrice = 10000, PriceBookEntryId = testdeliv4.id, OpportunityId = Opp.id) ); oli1.add( new OpportunityLineItem(Quantity = 1, TotalPrice = 10000, PriceBookEntryId = testdeliv5.id, OpportunityId = Opp.id) ); oli1.add( new OpportunityLineItem(Quantity = 1, TotalPrice = 10000, PriceBookEntryId = testdeliv6.id, OpportunityId = Opp.id) ); oli1.add( new OpportunityLineItem(Quantity = 1, TotalPrice = 10000, PriceBookEntryId = testdeliv7.id, OpportunityId = Opp.id) ); oli1.add( new OpportunityLineItem(Quantity = 1, TotalPrice = 10000, PriceBookEntryId = testdeliv8.id, OpportunityId = Opp.id) ); oli1.add( new OpportunityLineItem(Quantity = 1, TotalPrice = 10000, PriceBookEntryId = testdeliv9.id, OpportunityId = Opp.id) ); oli1.add( new OpportunityLineItem(Quantity = 1, TotalPrice = 10000, PriceBookEntryId = testdeliv10.id, OpportunityId = Opp.id) ); oli1.add( new OpportunityLineItem(Quantity = 1, TotalPrice = 10000, PriceBookEntryId = testdeliv11.id, OpportunityId = Opp.id) ); oli1.add( new OpportunityLineItem(Quantity = 1, TotalPrice = 10000, PriceBookEntryId = testdeliv12.id, OpportunityId = Opp.id) ); oli1.add( new OpportunityLineItem(Quantity = 1, TotalPrice = 10000, PriceBookEntryId = testdeliv13.id, OpportunityId = Opp.id) ); oli1.add( new OpportunityLineItem(Quantity = 1, TotalPrice = 10000, PriceBookEntryId = testdeliv14.id, OpportunityId = Opp.id) ); oli1.add( new OpportunityLineItem(Quantity = 1, TotalPrice = 10000, PriceBookEntryId = testdeliv15.id, OpportunityId = Opp.id) ); oli1.add( new OpportunityLineItem(Quantity = 1, TotalPrice = 10000, PriceBookEntryId = testdeliv16.id, OpportunityId = Opp.id) ); oli1.add( new OpportunityLineItem(Quantity = 1, TotalPrice = 10000, PriceBookEntryId = testdeliv17.id, OpportunityId = Opp.id) ); oli1.add( new OpportunityLineItem(Quantity = 1, TotalPrice = 10000, PriceBookEntryId = testdeliv18.id, OpportunityId = Opp.id) ); /* oli1.add( new OpportunityLineItem(Quantity = 1, TotalPrice = 10000, PriceBookEntryId = testdeliv19.id, OpportunityId = Opp.id, Prod_Grp__c = 'International - Platform') ); oli1.add( new OpportunityLineItem(Quantity = 1, TotalPrice = 10000, PriceBookEntryId = testdeliv20.id, OpportunityId = Opp.id, Prod_Grp__c = 'International - Coaching') );*/ } insert oli1; delete oli1; test.stoptest(); } }
All Answers
And further in trigger, htere is one problem.
In "Before Insert" trigger oli.Id will be NULL. So maybe this is the problem.
Fellow Force.com MVP Matt Lacey has a blog post on this topic here: http://www.laceysnr.com/2012/04/seealldata-why-i-think-you-shouldnt-use.html
System.QueryException: List has no rows for assignment to SObject
Class.TestOppUpdates.TestOppUpdates: line 132, column 1
Which is line 144 in the above code. Any idea why that might be happening now?