You need to sign in to do that
Don't have an account?
Bob_z
CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY & NVALID_CROSS_REFERENCE_KEY,
I am trying to deploy a trigger and a test class to my production org and I'm recieving a couple of errors. Below is the error lesssage I recieved while using Eclipse to deploy them.
Although the issue is probalby something simple to fixe I've tried several different changes with no success. I have the Trigger and the Apex test class below. If anyone could help me with this issue I would really appreciate it.
Test Class:
Trigger:
Run Failures: TestAfterPOLogUpdateTest.myUnitTest System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, TriggerNewYushinProd: execution of AfterInsert caused by: System.DmlException: Insert failed. First exception on row 0; first error: INVALID_CROSS_REFERENCE_KEY, Record Type ID: this ID value isn't valid for the user: 012180000004huPAAQ: [RecordTypeId]
Although the issue is probalby something simple to fixe I've tried several different changes with no success. I have the Trigger and the Apex test class below. If anyone could help me with this issue I would really appreciate it.
Test Class:
@isTest private class TestAfterPOLogUpdateTest { static testMethod void myUnitTest() { // TO DO: implement unit test test.startTest(); Opportunity opp = new Opportunity( Name ='Bob Inc.',polgid__c ='a4C39000000QFFiEAO', AccountId ='0017000000NAEsZ',StageName='Quoting',Who_is_quoting__c='Inside Sales', Type='EOAT', LeadSource ='NPE 2018', Describe_what_you_need_quoted__c='I need this test to work', Product_Type__c='Robot', CloseDate=System.today() ); insert opp; opp.polgid__c ='a4C39000000QFFiEAO'; opp.OwnerId ='0053900000614sS'; opp.Who_is_quoting__c='Inside Sales'; opp.Product_Type__c='Conveyor'; update opp; Yushin_Product__c yus = new Yushin_Product__c (); yus.Account__c ='0017000000NAEsZ'; yus.Opportunity__c='0063900000sutn9'; yus.PO_Log__c='a4C39000000QFKO'; yus.Equipment_Type__c= 'A-Axis'; yus.Model__c=''; yus.Product_Detail_Report__c = 'EOAT-SM'; yus.Discharge_Direction__c ='Clamp Traverse'; insert yus; yus.Equipment_Type__c = 'Servo Trav 600 and under'; yus.Model__c='RCII-100S-11-8.5'; yus.Product__c = 'RCII-100S-11-8.5'; yus.Price__c =45080; yus.IMM_Mfr__c = 'Toshiba'; yus.Status__c ='Sold'; yus.Booked_Date__c = Date.newInstance(2016, 12, 9); yus.PO_Log__c='a4C39000000QFKO'; yus.Discharge_Direction__c ='Clamp Traverse'; yus.Product_Detail_Report__c = 'EOAT-SM'; yus.Discharge_Direction__c ='Clamp Traverse'; update yus; yus.Equipment_Type__c = 'Installation'; yus.Product_Detail_Report__c = 'Installation'; update yus; yus.Equipment_Type__c = 'EOAT'; yus.Price__c = 499; yus.Model__c=''; update yus; yus.Equipment_Type__c = 'Safety Guarding'; yus.Product_Detail_Report__c = 'AUTO-SM'; update yus; yus.Equipment_Type__c = 'Conveyor'; update yus; yus.Equipment_Type__c = 'Servo Trav over 600'; update yus; yus.Equipment_Type__c = 'Adapter Plate'; update yus; yus.Equipment_Type__c = 'A-Axis'; update yus; yus.Equipment_Type__c = 'B-Axis'; update yus; yus.Equipment_Type__c = 'Freight'; update yus; yus.Equipment_Type__c = 'Degating Station'; update yus; yus.Equipment_Type__c = 'Installation'; update yus; yus.Equipment_Type__c = 'Hybrid'; update yus; yus.Equipment_Type__c = 'Software'; update yus; yus.Equipment_Type__c = 'Servo Traverse Super Large 1300 and greater'; update yus; yus.Equipment_Type__c = 'Spacer'; update yus; yus.Equipment_Type__c = 'Stanchion'; update yus; yus.Equipment_Type__c = 'Robot'; update yus; yus.Equipment_Type__c = 'System - SMALL'; update yus; yus.Equipment_Type__c = 'Collaborative robot'; update yus; yus.Equipment_Type__c = 'Side-entry (horz)'; update yus; yus.Equipment_Type__c = 'Side-entry (Vert)'; update yus; yus.Equipment_Type__c = 'Parts'; update yus; PO_Log__c pol = new PO_Log__c( Customer__c='0017000000NAEsZ',Opportunity__c='0063900000sutn9',Yushin_Product__c='a0639000020MH67', Order_Type__c='EOAT' ); insert pol; pol.Opportunity__c ='0063900000sutn9'; pol.PO__c = '12345'; pol.Sales_Order_Number__c = '12453'; pol.Order_Type__c = 'Robot'; pol.AddPLogOpps__c = true; pol.Notes__c= 'text'; pol.Order_Configuration__c = 'ATC'; pol.Sales_Order_Number__c = '189345'; pol.AddPLogOpps__c = true; update pol; test.stopTest(); } }
Trigger:
trigger TriggerNewYushinProd on Opportunity ( after insert, after update) { List<Yushin_Product__c> yus = new List<Yushin_Product__c>(); List<Yushin_Product__c> yusToDelete = new List<Yushin_Product__c>(); Map<Id, List<Yushin_Product__c>> existingYusMap = new Map<Id, List<Yushin_Product__c>>(); for(Yushin_Product__c yu :[SELECT Id, Opportunity__c, Account__c, Equipment_Type__c from Yushin_Product__c where Opportunity__c IN :Trigger.newMap.keyset()]){ List<Yushin_Product__c> yushinProducts = existingYusMap.get(yu.Opportunity__c); if (yushinProducts == null) { yushinProducts = new List<Yushin_Product__c>(); } yushinProducts.add(yu); existingYusMap.put(yu.Opportunity__c, yushinProducts); } for(Opportunity o : Trigger.new) { if (Trigger.IsInsert || Trigger.oldMap.get(o.Id).Product_Type__c == null) { if(o.Product_Type__c != null && o.Product_Type__c.contains('Robot')) { Yushin_Product__c y=new Yushin_Product__c(); y.Opportunity__c=o.Id; y.Account__c=o.AccountId; y.Equipment_Type__c='Robot'; y.RecordTypeId='012180000004huP'; yus.add(y); } if(o.Product_Type__c != null && o.Product_Type__c.contains( 'EOAT')) { Yushin_Product__c y=new Yushin_Product__c(); y.Opportunity__c=o.Id; y.Account__c=o.AccountId; y.Equipment_Type__c='EOAT'; y.RecordTypeId='012180000004huU'; yus.add(y); } if(o.Product_Type__c != null && o.Product_Type__c.contains('Conveyor')) { Yushin_Product__c y=new Yushin_Product__c(); y.Opportunity__c=o.Id; y.Account__c=o.AccountId; y.Equipment_Type__c='Conveyor'; y.RecordTypeId='012180000004huZ'; yus.add(y); } if(o.Product_Type__c != null && o.Product_Type__c.contains('Other')) { Yushin_Product__c y=new Yushin_Product__c(); y.Opportunity__c=o.Id; y.Account__c=o.AccountId; y.Equipment_Type__c='Other'; yus.add(y); } } else if (Trigger.IsUpdate && Trigger.oldMap.get(o.Id).Product_Type__c != null) { if(o.Product_Type__c != null && o.Product_Type__c.contains('Robot') && !Trigger.oldMap.get(o.Id).Product_Type__c.contains('Robot')) { Yushin_Product__c y=new Yushin_Product__c(); y.Opportunity__c=o.Id; y.Account__c=o.AccountId; y.Equipment_Type__c='Robot'; y.RecordTypeId='012180000004huP'; yus.add(y); } if((o.Product_Type__c == null || !o.Product_Type__c.contains('Robot')) && Trigger.oldMap.get(o.Id).Product_Type__c.contains('Robot')) { List<Yushin_Product__c> yPs = existingYusMap.get(o.Id); for (Yushin_Product__c yP : yPs) { if (yP.Equipment_Type__c == 'Robot') { yusToDelete.add(yP); } } } if(o.Product_Type__c != null && o.Product_Type__c.contains('EOAT') && !Trigger.oldMap.get(o.Id).Product_Type__c.contains('EOAT')) { Yushin_Product__c y=new Yushin_Product__c(); y.Opportunity__c=o.Id; y.Account__c=o.AccountId; y.Equipment_Type__c='EOAT'; y.RecordTypeId='012180000004huU'; yus.add(y); } if((o.Product_Type__c == null || !o.Product_Type__c.contains('EOAT')) && Trigger.oldMap.get(o.Id).Product_Type__c.contains('EOAT')) { List<Yushin_Product__c> yPs = existingYusMap.get(o.Id); for (Yushin_Product__c yP : yPs) { if (yP.Equipment_Type__c == 'EOAT') { yusToDelete.add(yP); } } } if(o.Product_Type__c != null && o.Product_Type__c.contains('Conveyor') && !Trigger.oldMap.get(o.Id).Product_Type__c.contains('Conveyor')) { Yushin_Product__c y=new Yushin_Product__c(); y.Opportunity__c=o.Id; y.Account__c=o.AccountId; y.Equipment_Type__c='Conveyor'; y.RecordTypeId='012180000004huZ'; yus.add(y); } if((o.Product_Type__c == null || !o.Product_Type__c.contains('Conveyor')) && Trigger.oldMap.get(o.Id).Product_Type__c.contains('Conveyor')) { List<Yushin_Product__c> yPs = existingYusMap.get(o.Id); for (Yushin_Product__c yP : yPs) { if (yP.Equipment_Type__c == 'Conveyor') { yusToDelete.add(yP); } } } if(o.Product_Type__c != null && o.Product_Type__c.contains('Safety Guarding') && !Trigger.oldMap.get(o.Id).Product_Type__c.contains('Safety Guarding')) { Yushin_Product__c y=new Yushin_Product__c(); y.Opportunity__c=o.Id; y.Account__c=o.AccountId; y.Equipment_Type__c='Safety Guarding'; y.RecordTypeId='012180000004hue'; yus.add(y); } if((o.Product_Type__c == null || !o.Product_Type__c.contains('Safety Guarding')) && Trigger.oldMap.get(o.Id).Product_Type__c.contains('Safety Guarding')) { List<Yushin_Product__c> yPs = existingYusMap.get(o.Id); for (Yushin_Product__c yP : yPs) { if (yP.Equipment_Type__c == 'Safety Guarding') { yusToDelete.add(yP); } } } } } if(yus.size()>0) insert yus; if(yusToDelete.size()>0) database.delete(yusToDelete); }
Repeat the same step for the record types in trigger and test class
I will give it ago.
System.DmlException: Insert failed. First exception on row 0; first error: INVALID_CROSS_REFERENCE_KEY, Record Type ID: this ID value isn't valid for the user: 012180000004huPAAQ: [RecordTypeId]. (I had the wrong ID in the test class) I havent been able to resolve the TestAfterPOLogUpdateTest.myUnitTest System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, TriggerNewYushinProd: execution of AfterInsert.
trigger TriggerNewYushinProd on Opportunity ( after insert, after update) {
}
I tried changing the code to below, Knowing the test would probably fail. It did and it gave me the same error message as it does when i add the fields in the test to insert as you can see below. So I'm not sure how to get this to work.
No matter what i try it doesnt like Trigger.TriggerNewYushinProd: line 8, column 1: []
Insert with the fields:
I was wonder since you help me out with this trigger if you could help me add a qaunity field in my trigger. I have a new fields i just created entitled "Robot_Qauntity__c" "EOAT_Qauntity__c" "Software_Qauntity__c". What i'm trying to do is add them into the trigger so when i user select robot they select how many products to create of that particular product. I'm not quite sure if i can add this to the trigger or how to add it. Any help would be greatly appreciated.