I'm looking to retrieve the string value for the Inventory_Stage__c field in the following logic. The code is incomplete, but I'll post the relevant stuff of what I have. Any help in doing this would be greatly appreciated. Thanks in advance! I'll explain what I think is happening here - I'm a bit new to this so if my logic is wrong here, please advise.
Here I'm building a map of all the Transaction__c records with a start date from this week (Renamed to Production Orders or Production Shifts elsewhere). I am setting the key to the Name of the Inventory_Stage__c and the value to the Transaction__c object.
Map<String, Transaction__c> thisWeeksShifts = new Map<String, Transaction__c> ();
for (Transaction__c p : [SELECT Id, Name, Inventory_Stage__r.Name FROM Transaction__c WHERE Shift_Start__c = THIS_WEEK]) {
String p_name = p.Inventory_Stage__c;
thisWeeksShifts.put(p_name, p);
}
And here I'm trying to loop over all the Inventory Transactions in the trigger and get the Production Shift for which the Inventory_Stage__c in the Production Shift (Transaction__c) matches that of the Inventory_Stage__c in the Inventory Transaction so I can assign it as the parent in the new record I'm creating. I'll also eventually want to assign the Inventory_Stage__c of the cloned inventory transaction to the inventory stage of the current parent Transction__c object.
for(Inventory_Transaction__c invTrans : Trigger.new) {
if (invTrans.Type__c == 'Out') {
SObject nextProductionOrder = (String) thisWeeksShifts.get(invTrans.getSobject('Production_Shift__r').get('Inventory_Stage__c'));
system.debug(thisWeeksShifts.size());
Inventory_Transaction__c invTransNew = invTrans.clone(false, true, false, false);
invTransNew.Type__c = 'In';
toClone.add(invTransNew);
}
}