You need to sign in to do that
Don't have an account?
daniel1110
Trigger: Update record of different record type with same field values
Hi. I am trying to update some fields with values from another record with a different record type. Nothing happens when I try the following code. Pls help
trigger createOrderforABFSCB1 on Stem_Cell_Bank__c (after update) { // Collect all updated SCB Ids Set<Id> setSCBIds = new Set<Id>(); // Collect all SCB Id which has stem cell banked date populated for(Stem_Cell_Bank__c scb : Trigger.new) { if (scb.Stage__c == 'Stem Cells Banked' && Trigger.oldMap.get(scb.Id).Stage__c != 'Stem Cells Banked') { setSCBIds.add(scb.Id); } } // List for collecting Orders to update List<ChargentOrders__ChargentOrder__c> colist = new List<ChargentOrders__ChargentOrder__c>(); // Iterate all the Orders of SCB for(ChargentOrders__ChargentOrder__c o : [SELECT Id, Account__c, Stem_Cell_Bank__c, ChargentOrders_Expiration_Month__c, ChargentOrders_Number__c, ChargentOrders_Type__c, ChargentOrders__Payment_Method__c, RecordTypeId FROM ChargentOrders__ChargentOrder__c WHERE Stem_Cell_Bank__c IN: setSCBIds]) { if(o.RecordTypeId == '012E0000000VPOC') { colist.add(new ChargentOrders__ChargentOrder__c(Id = o.Id, RecordTypeId = '012E0000000VPOH', ChargentOrders_Number__c = o.ChargentOrders_Number__c)); } } if(!colist.isEmpty()) { update colist; } }
Also, it's a horrible idea to hardcode Ids of any type, RecordType or otherwise. Verify that the Ids are correct, but I would stick them in a custom setting so that you can change them easily between production and sandbox instances if need be.
I tried to taking out the hardcode Ids, but now left with an error: 16:58:22:285 USER_DEBUG [47]|DEBUG|System.DmlException: Insert failed. First exception on row 0; first error: INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY, insufficient access rights on cross-reference id: a0QE0000003NfYt: []
Here's my updated code. Any other suggestions?