Today's 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.
- Trigger on the Order Object:
Line 3: For when a brand new order is added with a tracking number
Line 7: For when the tracking number field is updated
1. The trigger Handler class:
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.
1. The @Test class, is needed for the code coverage to be able to deploy into production.
Any questions, please do not hesitate to contact us!