Zenkraft Blog

Run your Logistics and Post-Purchase Experience on the Salesforce Platform.

Create a scheduled job code to delete any FedEx checkpoints for shipments that have been delivered more than 2 week ago

Published on 04 October 2017 by in  

Todays blog post will show you the code needed to set up a scheduled job that will remove all FedEx checkpoint objects for shipments that have been delivered more than 2 weeks ago.

This is useful if you are coming up against salesforce storage limits and need to clear out some space.

We will need to create two classes and then their respective test classes.


This class creates the list of all the checkpoints that need to be deleted.

Line 7 creates the SELECT query, and Line 15-16 is where the DELETE statement is executed.


This class is needed to execute the RemoveDeliveredCheckpointsBatch above, and will be the class that we use the Schedule Apex on your production instance, once these classes have been deployed.


The test class for RemoveDeliveredCheckpointsBatch


The test class for RemoveDeliveredCheckpointsScheduler

Next you need to create the changeset and deploy these classes into your production environment.

Once in your production environment you need to go to Setup > Develop > Apex Classes and click on the schedule Apex button:

Fill in the details and remember to input RemoveDeliveredCheckpointsScheduler into the Apex class field.

If you want the job to run everyday at 5am then set up the page like so:

Click Save, and you’re finished.

Please let us know if you have any questions and we will be happy to help.

Continue reading »

Bulk Cancel UPS shipments

Published on 18 July 2017 by in  

A quick code snippet for you today, if you want to cancel all UPS shipments that have not been picked up.

Here is the code to run in Developer Console:

Line 4 determines the shipments we want to set as cancelled. For this snippet we have decided to cancel all shipments older than UPS-Shipment-0000001000.

Line 7 then uses our startMassShipmentCancelBatch process that goes through all the shipments and cancels them.

Please contact us if you have any questions and we will be glad to help.

Continue reading »

Using Process Builder to Add FedEx Tracking Number to your Contact Object

Published on 11 July 2017 by in  

Today's blog post will show you how add the FedEx Tracking Number onto the Contact object after you have created a shipment.

Firstly make sure you have the text field available on your contact object:


Next let’s create a Process Builder task to retrieve the tracking number once the shipment has been created.

To access the process builder page, go to Setup > Create > Workflow & Approvals > Process Builder

Click on “New” and give it a name. We want to start this process when “A record changes” , so select that from the dropdown. This is what you should see:

You are now presented with this blank process builder screen.

Click on the “Add Object” button and select the “FedEx Shipment” object. We need to start the process only when a record is created.


The next step is to “Add Criteria”, and we want to ensure that there is a relationship to the contact object. We do this by filling in these fields here.

Here is the closer look at the “Field” value we have chosen


Next we click on “Set Schedule” and set the time for actions to execute at “0 Days After CreatedDate”

We do this as it creates a small delay after the shipment has been created, which ensures the shipment creation process is not blocked.

Next we need to select which records to update. Make sure you select “Recipient Contact”, and not “Recipient Contact >” as there is a big difference.


Next set the field value you want to update on the Contact object, which in our case is “FedEx Tracking Number”.

The Value field we are using is the Master Tracking Number as you can see here.


That’s it, lets activate it and do a test shipment from the contact object, and you should then see the tracking number appear like so:

If you have any issues then please contact us and we would be glad to help.

Continue reading »

Using Process Builder to send a custom email after shipment creation

Published on 04 July 2017 by in  

Here is a quick guide to show you how you can send an email to the recipient’s email address to let them know they shipment has been created and is being sent today, by using the integrated SalesForce Process Builder.

First you need to set up a new Process Builder task. Go into Setup > Process Builder and click on the New button in the top right hand side of the page, and fill in the details and click Save.


Click on “Add Object” and then search for “UPS Shipment object”, then Click “Save”

Next is adding the criteria requirement. We only want to run this task if there is an email address in the recipient field on the shipment object. So let’s set that up by first filling in the “Criteria Name”, and then clicking on the field and selecting recipient email.

We want to make sure that the email address at least has an @ sign in it, so we create the criteria as follows:

Next we will setup a Scheduled Action, to run 0 days after Created Date. We do this because we need this process builder task to run AFTER the shipment has been created. This ensures nothing blocks the shipment creation process. By setting the scheduled action to run after 0 days after shipment creation essentially means this process only runs a few seconds after the shipment creation.

You can see how this section should now look.

Click Save and let’s create the Action associated with this schedule.

We are going to create a new email alert and then the new template, but if you already have one ready to go, then just add it to the Email Alert box.

We will show you the steps needed in case you haven’t got them ready yet.

Click on “Create one”.

This takes you to the new Email Alert screen. Make sure you give this email alert a description, select UPS Shipment from the dropdown. You will then be able to find the “Email Field: Recipient Email and move it into the selected Recipients box.

The last thing we are missing is the Email template. So to do this we need to open a new tab and go to Setup > Communication Templates > Email Templates. Click the “New template” button to start creating your template email.

To keep things simple for this tutorial we will just create a text based email.

Give your email template a name, and add a subject line and email body.

To merge any fields into the subject or body of the email, select the first dropdown on the page under the “Available Merge Fields” heading, and select “UPS Shipment Fields” and the field you want to merge. You will then be able to copy and paste the variable that starts with {! and ends with }.

Once you have set up this email template Save it and go back to your Email Alert screen and add the newly created template as you can see here.

The final step is to add this email alert to your Process Builder task which you can see here:

Click save and make sure to Activate this Process Builder Task.

It’s always good to do a quick test to confirm its all working as expected.

Contact us if you have any queries.

Continue reading »