Skip to main content
added 100 characters in body
Source Link
Eric
  • 54.4k
  • 11
  • 104
  • 196

Ok, someone will correct me if I am wrong as I do not use that method very often butand I can only get it to work when including the __r.Name in the query which the trigger does not have. I do not think you can use it in this scenario.

You are going to have to get a Set for all the Production_Shift__c and the create a map to use for the values

i.e.

Set<ID> parentIDs = New Set<ID>();
for(Inventory_Transaction__c invTrans : Trigger.new) {
    if(invTrans.Production_Shift__c != null) parentIDs.add(invTrans. Production_Shift__c);
}

Map<ID,Production_Shift__c> shitMap = New Map<ID,Production_Shift__c>([Select ID, OtherFields From Production_Shift__c Where ID IN :parentIDs]);

Then cycle through the trigger records again and use the map to get your values

   for(Inventory_Transaction__c invTrans : Trigger.new) {

     If(shiftMap.containsKey(invTrans.Production_Shift__c){ //If is probably not necessary as they should be there
             //Do your stuff
     }

}

Ok, someone will correct me if I am wrong as I do not use that method very often but I do not think you can use it in this scenario.

You are going to have to get a Set for all the Production_Shift__c and the create a map to use for the values

i.e.

Set<ID> parentIDs = New Set<ID>();
for(Inventory_Transaction__c invTrans : Trigger.new) {
    if(invTrans.Production_Shift__c != null) parentIDs.add(invTrans. Production_Shift__c);
}

Map<ID,Production_Shift__c> shitMap = New Map<ID,Production_Shift__c>([Select ID, OtherFields From Production_Shift__c Where ID IN :parentIDs]);

Then cycle through the trigger records again and use the map to get your values

   for(Inventory_Transaction__c invTrans : Trigger.new) {

     If(shiftMap.containsKey(invTrans.Production_Shift__c){ //If is probably not necessary as they should be there
             //Do your stuff
     }

}

Ok, someone will correct me if I am wrong as I do not use that method very often and I can only get it to work when including the __r.Name in the query which the trigger does not have. I do not think you can use it in this scenario.

You are going to have to get a Set for all the Production_Shift__c and the create a map to use for the values

i.e.

Set<ID> parentIDs = New Set<ID>();
for(Inventory_Transaction__c invTrans : Trigger.new) {
    if(invTrans.Production_Shift__c != null) parentIDs.add(invTrans. Production_Shift__c);
}

Map<ID,Production_Shift__c> shitMap = New Map<ID,Production_Shift__c>([Select ID, OtherFields From Production_Shift__c Where ID IN :parentIDs]);

Then cycle through the trigger records again and use the map to get your values

   for(Inventory_Transaction__c invTrans : Trigger.new) {

     If(shiftMap.containsKey(invTrans.Production_Shift__c){ //If is probably not necessary as they should be there
             //Do your stuff
     }

}
Source Link
Eric
  • 54.4k
  • 11
  • 104
  • 196

Ok, someone will correct me if I am wrong as I do not use that method very often but I do not think you can use it in this scenario.

You are going to have to get a Set for all the Production_Shift__c and the create a map to use for the values

i.e.

Set<ID> parentIDs = New Set<ID>();
for(Inventory_Transaction__c invTrans : Trigger.new) {
    if(invTrans.Production_Shift__c != null) parentIDs.add(invTrans. Production_Shift__c);
}

Map<ID,Production_Shift__c> shitMap = New Map<ID,Production_Shift__c>([Select ID, OtherFields From Production_Shift__c Where ID IN :parentIDs]);

Then cycle through the trigger records again and use the map to get your values

   for(Inventory_Transaction__c invTrans : Trigger.new) {

     If(shiftMap.containsKey(invTrans.Production_Shift__c){ //If is probably not necessary as they should be there
             //Do your stuff
     }

}