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 shipment from a Case object when the Status field on the Case object gets set to "Return Approved".
Step 1. Set all required fields
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 UPS_GROUND, UPS_NEXT_DAY_AIR, UPS_NEXT_DAY_AIR_SAVER. A full list of these values can be found here.
Default Package Type Field : such as UPS_YOUR_PACKAGING, UPS_LETTER, UPS_MEDIUM_EXPRESS_BOX. 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
Step 2: Create 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 Case object, and we will be running the shipment creation once the Case Status field is set to "Return Approved".
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 Status field is set to "Return Approved".
Next add an Immediate Action. The Action Type will be "Apex", and the Apex Class will be "Create Shipment".
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 Case ID.
Once set up correctly, it should look like this:
If you want to Auto Print the labels after they have been printed you can set the isAutoPrint to True as a new variable like so:
Or you can set this on your Custom Address Source via the checkbox:
The "isAutoPrint" process builder variable will overwrite the Custom Address Source checkbox if set.
Click Save, and don't forget to Activate this Process Builder.
That is all set, you will now be able to have shipments created via process builder.
Once you have activated the process builder, go to a Case, change its Status to “Return Approved” and a shipment will be auto-created.
If you have missed a step and the shipment isn’t created, you can view error message under Setup > Jobs > Apex Jobs.
The error messages are extremely helpful in debugging. For example, you can see that in the below screenshot the Shipmate Preference was missing and at another time the Shipping Date was missing and finally the Bill Transportation To was missing.
The top most job shows that the process completed successfully.
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.