Zenkraft Blog

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

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 »

UPS Address validation on an Account

Published on 23 May 2017 by in  

Today's blog post will show the code you need to validate an Account address via the UPS Address Validation call you can find in the UPS Shipmate app.

Firstly we will look at the Controller code, and we will explain how it works below:

Lines 7-12: This is where you specify the name of the Account object that you want to validate the address for.

Lines 14-27: We need to get the details of our UPS Shipmate preference and store it into the shipmatePref variable.

Line 29: We create a new zkups_UPSShipment__c object that we will then use to run the validation method against.

Lines 30-34: We add the Account address details to the UPS Shipment object we created in line 29.

Line 36: We create the ValidateAddressResult which is populated by the zkups.ShipmentInterface.validateAddress method. The validateAddress method is the point at which we make the API call out to UPS.

Line 37 – 39: We check if the UPS web service has returned any results, and if so we add it to the validationAddressesList list.

Here is the Visualforce page code that you could link to from the account page that will show you the results of the UPS Address validation results.

Any questions, please do not hesitate to contact us!

Continue reading »

Create a button to replicate the Custom Address Source “New Shipment Functionality”

Published on 26 April 2017 by in  

Today we will show you how to create a custom button on your object that does the same as the New Shipment button from your related list.

The most usual use case for this is if you want to create 2 one click shipment buttons from a standard or custom object. One for a standard outbound shipment, and the other for a return shipment.

For this demo we will use the standard Case object. The first thing we need to do is make sure our Custom Address Source related lists already added to the page. If you haven’t set up your custom address sources for one click shipping please look at the documentation found on our docs page here:

Once you have your two related lists on the page like so:

Two Related Lists

Click on the first button and copy the resultant URL

Two related lists

You should get something like this:

Paste this URL somewhere you can get to it later on, we will need it.

Next go to Setup > Customize > Cases > Buttons, Links, and Actions

Click the “New Button or Link” button.

Buttons, Links and Actions

Enter a Label and Name. Select “Detail Page Button”. Under the Behaviour select “Display in existing window without sidebar or header.” Set the Content Source to be “URL”.

Remember the link you copied and put somewhere safe? Lets copy that and paste it into the text area.

There are three changes we need to make to the URL. Lets split out the URL so its easier to read. Every time you see the “&” or “?” press enter.

We should end up with something similar to this:


This is the point you need to insert a merge field.

The first one to replace is the “Case Number” of the Case object. In this example 00001026 will be replaced with this merge field{!Case.CaseNumber}

And the next two replacements of 500E000000VCQyo are the salesforce case ids, which are replaced with {!Case.Id} as you can see here.

Click save and you are done for this part.
The next step is to add this newly created button onto your case object. To do that navigate to any Case and click on Edit Layout.


Click on Buttons, and find the button you created earlier “Create USPS Shipment”, and drag it down into the Custom Buttons section.


Then click save.
Test out the button that has now appeared.


Hopefully that has now worked for you, and you can do the same steps to create the Create a Return USPS Shipment button, that linked to the second Custom Address Source button.

As always we are here to help so contact us for any queries.

Continue reading »

Add External FedEx tracking numbers from an Order

Published on 11 April 2017 by in apex fedex 

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!

Continue reading »

Send an email template with a GIF attachment

Published on 05 April 2017 by in  

Today we will show you how to send an email template with a GIF return label attached once a shipment is created from a Case.

Before you can write any code you need to set up three things;

  1. Email template
  2. Notification checkbox
  3. Create a new lookup relationship from the UPS Shipment to the Case object

First thing you need to do is create an email template. This you can do by going into Setup > Administer > Communication Templates > Email Templates

Create a new ‘custom’ template and name it “UPS Shipment

  1. Then add your html code and subject line. At this point you can add your merge fields as well. An example merge field that could be used is, if you have a list of brands that are related to the case. {!zkups__UPSShipment__c.Case_Brand__c}
  2. Secondly you need to create a new checkbox on the Case object, let’s call it “Zenkraft Notification”, it should then create a field called Zenkraft_Notification__c. This basically ensures the email is only sent once.
  3. Thirdly, go to Setup > Create > Object > UPS Shipment and create a new lookup relationship to the Case object. For our example the lookup relationship is New_Case__c.
  4. Finally we get to write some code, we’ve set this up as a scheduled job that runs once a day to send emails out:

Find the template you created earlier

Select UPS Shipments that you want to create emails for:

If you want to add a brand specific logo to each email then you need to use this code to get the name of the image from your SalesForce Documents folder. This is the code you need to use.

Finally this is the code you should use to bring it all together and send your emails out, and to update the Case object checkbox to true.

If you have any questions we would be glad to help.

Continue reading »