Our invocable method allows you to create a shipment from any object that you have set up a Custom Address Source for using Process Builder. If you haven't set up a Custom Address Source then please follow this guide that explains how to do so.
In this example we will create a rate request from an Opportunity object when the Status field on the Opportunity gets set to "Proposal/Price Quote".
Step 1. Add 4 fields onto your object
Add 4 custom fields onto your object (Opportunity in our case) where you will store the returned Rate information.
We recommend something like this:
Step 2. Set all required fields in your Custom Address Source
In your Custom Address Source you will need to have these items set as a minimum:
Recipient Address Fields:
Street 1 Text Line Field
Postal Code FIeld
Billing Field Names
Billing Field : the value of this field can be set to SENDER, RECIPIENT, THIRD_PARTY
Shipmate Preference Field : the value of this field can be set to the name of the preference. E.g "ShipmatePreference-0000"
Ship Date Field : ensure this is a date field. If you want to use todays date, just add this value to the formula field - TODAY
Domestic Service Type Field : such as FEDEX_2_DAY, FEDEX_GROUND, FIRST_OVERNIGHT. A full list of these values can be found here.
Default Package Type Field : such as FEDEX_BOX, FEDEX_ENVELOPE, YOUR_PACKAGING. A full list of these values can be found here.
You must add at least one package row. Fields needed are Quantity, Weight and Declared Value.
Auto Create Shipment must be checked
This section defines which fields on your original object (in our case the Opportunity object), you would like the rate information that is returned to be populated to.
Output Delivery Date Field : Expected delivery date
Output Net Charge : Estimated shipment cost
Output Delivery Day Of Week Field : Expected Delivery day of the week
Output Service Type Field : Service Type that was chosen
Step 3. Process Builder Task
Create a Process Builder Task by going to Setup > Create > Workflow & Approvals > Process Builder and click the New button.
Give the process a name, description and choose to start the process when "A record Changes".
Next choose the object you are starting the process from. Remember in this guide, we are using the Opportunity object, and we will be running the shipment creation once the Opportunity StageName gets set to "Proposal/Price Quote".
Make sure you set to "Start the process" to be "when a record is created or edited". Click Save, and then select "Add Criteria".
Fill in your requirements for when the shipment process should start. In this guide we are going to check that the Opportunity StageName gets set to "Proposal/Price Quote".
Next add an Immediate Action. The Action Type will be "Apex", and the Apex Class will be "Get Rate".
You will then be able to set the Apex Variables.
For the customAddressId please set it to the Custom Address Source ID that you are running this process from. To get this ID, navigate to your Custom Address Source and copy the last part of the URL. If you are in lightning just use the first 15 characters of this objectId.
For the recordId please set the Type as Field Reference, and the Value to be the Object ID. In our case it will end up being the Opportunity ID.
Your screen will now look like this:
Click Save, and don't forget to Activate this Process Builder.
That is all set, you will now be able to have rates information populated back onto your object via Process Builder.
Once you have activated the Process Builder, go to an Opportunity, change its Status to “Proposal/Price Quote” and your rate information will appear on your object.
If you have missed a step and the rate isn’t created, you can view error messages under Setup > Jobs > Apex Jobs.
The error messages are extremely helpful in debugging.
Please contact us using the icon to the bottom right of this screen if you have any queries, and we will be glad to help.