Updating a Parent Record After a Shipment is Created

You may want to update a parent object after a shipment has been created. It is possible to achieve this using a trigger on the shipment object.

In the example below we will show you how to check a checkbox on the case object after the shipment record has been created.

This will be useful to create workflow that could send emails, alert people, send chatter updates or endless other possibilities.

trigger UpdateRMAonShipment on zkfedex__Shipment__c (after insert, after update) {
   if(Trigger.new.size() == 1) { //Don't utilize trigger if a bulk update is occuring
           for (zkfedex__Shipment__c shipment : Trigger.new) {
               if (shipment.zkfedex__SsProcessReturnShipment__c == false) { //Ignore return labels
               if (shipment.RMA__c != null) {
                   RMA__c rma = null;
                   try {
                       rma = [SELECT Name, Tracking_Number_OUTBOUND__c from RMA__c where Id =: shipment.RMA__c limit 1];

                   } catch(Exception e) {
                       rma = null;
                   }
                   if (rma != null) {
                       rma.Tracking_Number_OUTBOUND__c = shipment.zkfedex__MasterTrackingId__c;
                       update rma;
                   }
               }
   }
  }
 }
}
Did this answer your question?