Add External FedEx tracking numbers from an Order

Todays blog post we will show you how to add an externally created FedEx tracking numbers to an object. Updating tracking is the most common use case, that you are then able to query using the standard salesforce reporting. We’ll be using the Order object in our demo here.

The code is made up of 3 parts.

  1. Trigger on the Order Object:
  2. Line 3: For when a brand new order is added with a tracking number

    Line 7: For when the tracking number field is updated

  3. The trigger Handler class:
  4. This is where the work gets done.

    Line 4: Here you will need to contact us to get the ModKey value that allows the creation of a Shipment Object (without actually going through our package for the shipment creation process).

    Line 8: You need to create a custom setting to store the ID of the preference, so that when you move this code from your sandbox org to your production org, its easy to update the custom setting to your saved UPS preference.

    Line 19-30: For any new Orders, add the new record to the createFedExShipment method.

    Line 30-47: If you are just updating the tracking number field (FB_Tracking_Numbers__c) on your Order, these lines take care of the shipment creation.

    Line 67-75: For each shipment we create we also need to create a shipment package (zkfedex__ShipmentPackage__c) associated with it.

  5. The @Test class, is needed for the code coverage to be able to deploy into production.
  6. Any questions, please do not hesitate to contact us!

About the author

Adrian Miotto
By Adrian Miotto