Zenkraft Blog

Zenkraft Blogs about Logistics, LSPs, Integration with CRM, ERP and WMS applications.

Multiple Package Returns for UPS and Auto Printing

Published on 28 February 2017 by in ups returns 

This weeks post will detail how to achieve the following using our package, and some apex code.

  • Multiple Package Returns for UPS
  • Auto Printing

Multiple Package Returns for UPS

Currently the UPS api only allows the creation of 1 return label at a time. So if you want to create 20 return labels at once you need to set up a batch process to create them individually but group them into a Bulk Shipment which then allows you to print them all off at once.

We first need a method to create our bulk shipments, which we then reference later on in a loop.

Line 2: create a new queuedShipment object.

Line 3: set this new queuedShipment to be in the bulkShipment object.

Line 4-9: Sets the payment type, service type, units, labeltype, packaging type and the account this shipment is related to.

Lines 12-20: sets the sender address from the shipping preference.

Lines 23-30: set the recipient address details from the account.

Liens 33-35: set the values needed to create a return shipment.


Then we utilise a loop for the number of labels we will be creating. The code to loop through and to eventually send the shipments to be created is here:

Line 5: Create the bulkShipmentId that we will then send for processing after we have created the queuedShipments

Lines 10-21: This is the for loop where we go through creating the list of queuedShipments and creating the packages that are also required.

Line 28: is where we send the bulkShipment to be processed.

Lines 44-55: show how to create the packages.


Auto Printing

Our package is already setup to auto print a shipment label and all related documents from the shipment view page. All you need is the salesforce id of the shipment that has been generated. After shipment creation, you need to redirect the user to the shipment using the code below, and as long as you have setup the users default printers in the “Manage Printers”, the printing of all the labels and documents related to that shipment will automatically print on the respective printers. For example if you have a thermal shipping label and an international document, they will be printed to the thermal printer and to the laser printer respectively.

String redirectUrl = ‘/apex/zkups__ShipmentViewV2?autoprint=1&id=’ & shipmentId;

Any questions, please contact us and we will be happy to help you out.

Continue reading »

Convert a GIF shipping label image to PDF

Published on 31 January 2017 by in apex salesforce 

In today’s blog post we’re going to show you the codes needed to convert a GIF shipping label into a PDF document.

We’re going to use pages, classes, and controllers.

APEX Class

The first method we need to look at is regenerateGifToPdfLabel (line 2). The steps are as follows:

The createPDFLabels (line 25) method in step 3 above calls the generatePDFLabel method (line 35).

Next create a new attachment object pdfLabel, which will be the PDF file (line 36). Line 38 is where we reference our VisualForce page, that will contain the original GIF file. The VisualForce page code can be found at the bottom of this post.

Line 41 sets the Body of the new attachment object as the blob that is returned from the standard SalesForce method getContentAsPDF();.

APEX Controller

Line 6-7 basically set the variable that will be used in the VisualForce page.

VisualForce Page

Line 25 is where the GIF shipping label is inserted, which is then rendered as a pdf from the code we have already looked at from above.

Happy coding.

Continue reading »

Part 3 of 3: Pick and Pack Station with ERP Integration

Published on 23 January 2017 by in salesforce 

A few weeks ago we wrote about our Pick and Pack implementation, detailing how we’ve created the system, the custom labels and automated custom printing.

Today we will expand on this to show you how we can integrate with one of the ERP solutions that are available on salesforce. We will use Rootstock as an example.

One function of ERP systems are to manage the process for inventory for Picking, Packing and Shipping. In this post we will discuss the Packing and Shipping part of the process and the API calls needed to the Rootstock system to achieve this.

The process that we use is as follows:

1. Put all packed items into Custom Objects called Shipping Containers.

2. Depending on whether all the items are being shipped at once (Full shipment) or in batches (Partial shipment) we make different calls to the Rootstock api and create the Rootstock Shipper object.

3. Create the Container Objects and attach the newly created Zenkraft Shipping label information to them.

Here are the steps in more detail:

1. If we look back at our pick and pack screenshot here:[caption id="" align="alignnone" width="1248"]

Pick and Pack Station in Salesforce[/caption]

We store the items you can see in the “In Progress Containers” section within our own Custom objects called Shipping Containers. There is no interaction with Rootstock at this stage as we are just preparing the information ready to create a Rootstock Shipper.

2. Once the user clicks the “Finish Button”, we make a call to the Rootstock API to signal the items that have been packed, and request a new shipper to be created.The two key points to keep in mind here are whether the shipment is a FULL or PARTIAL shipment.FULL:A FULL pack order is when ALL the items on the Sales Order have been packed and are ready to be shipped. On the Rootstock side, this gets processed straight away.

In the code example below, we set the transaction type (line 2) to ‘Sales Order Pack’, we set the background processing (line 5) to false, and the all lines variable (line 6) to true. Line 6 specifies that this is a full shipment type.


A partial shipment is when you might have a very large order, but there are some items that haven’t been picked as available yet in the packing warehouse meaning that the order cannot be completed in 1 shipping session.

As there could be hundreds of lines have been packed we need to be careful to not hit any Salesforce SOQL limits, which is why we use the code below to ensure these limits do not get hit and end up with an error.

Line 8 is where we specify this is a partial shipment by setting alllines__c = false, and line 9 is setting backgroundprocessing__c = true. For each of these individual line items that are being packed we need to create a transaction, which we then send to be processed by the Rootstock ERP on line 19.

3. Once the items have been marked as packed and the shipper has been created, we set our queued bulk shipping process to start creating the shipping label.The next set is to create the Rootstock Container Objects which we do using this code:  

We set all the container fields from line 2-19, with line 19 adding the new shipments tracking number.

And that is how we are able to integrate our Pick and PACK station with an ERP system.

Continue reading »

The new Multi-Carrier Shipping App for Salesforce is now Live on AppExchange!

Published on 10 January 2017 by in multi-carrier ecommerce salesforce 


Shipping inside Salesforce just got better, with the introduction of the new Multi-Carrier Shipping app to the AppExchange. Users can now choose between 30+ carriers to manage their logistics within the CRM platform(Multi-Carrier supports all Salesforce Editions: Group, Professional, Enterprise, Unlimited,, Developer, Performance).

Today, Salesforce users can create shipments, schedule pickups, track, and set up automation rules for carriers such us: DHL, Parcel Post, Canada Post, Australia Post and TNT.

You can find a full list of the supported carriers on our multi-carrier product page. We aim to add several new carriers each month over the coming years.

Like our FedEx, UPS and USPS shipping apps for Salesforce®, the Multi-Carrier app also brings great features to businesses searching for solutions in the AppExchange ecosystem. Companies can benefit from:

  • Sending mail or shipping packages to any Lead, Contact, Account, Opportunity or any custom object
  • Saving time with One-click shipping
  • Calculating and comparing rates
  • Generating and printing labels to standard and thermal printers
  • Tracking shipments automatically
  • All this and more without ever leaving Salesforce

Because we build our apps natively on, users can seamlessly integrate with all the order management and supply chain management apps that businesses currently use, like Kenandy, Accounting Seed, Conga Composer, Glovia, Ascent, Cloud Conversion, ChikPea, Veeva, Rootstock and FinancialForce.

Sound interesting? Book a meeting with one of our team for a personalized demo.

Can’t wait? Get started now, go to Multi-Carrier in AppExchange and start your free trial today!

Continue reading »

Bulk Shipping From a List View in Salesforce

Published on 13 December 2016 by in apex salesforce bulk shipping 

Today we are going to create shipments in bulk from the Contacts list view. By the end of this tutorial you will be able to add a button to the contacts list view as you can see here:


This will take you to the preview and bulk processing page here:


Once the shipments have been processed you will be redirected to the printing page:


Below are the steps:

1. Create the visualforce page. Code is below:


Make a note of line 11 above, this is the poller that runs every 5 seconds once we have sent our shipments to be processed. It’s used to check the current status of the bulk processing. If there are errors it will display them, or if the process completes successfully you will be redirected to the printing page.

2. Now, the main part of the programming takes places, which is our controller. Here is the full code snippet, and we will explain sections of it below:


The controller retrieves the list of selected contacts and creates a queued shipment object for each of them. Once that’s completed, we add this list of queued shipments to a bulkshipment object and then request the processing of this bulkshipmentobject via the processbulkshipments method.

Lines 6-8 retrieves the IDs of the contacts that we have selected on the previous page and Lines 10-15 selects the relevant shipping information for each of those contacts:


The next code block gets called when we click on the CreateShipments button on the VisualForce page we created earlier. The first thing we need to do is to create the BulkShipmentID that we will be adding all the queued shipments to (Line 6).

Lines 7-12 is where we create one queued shipment for each contact that has been selected, and add it to the queuedPackagesList. Line 9 is where we call the createQueuedShipmentRecord method, and we will explain this method a little later in this blog post.


For each queued shipment we have to create the package information so that UPS knows the weight and value of each package (Line 14-23).

At Line 26 we set the bulk Shipment to start the validation process, and Line 28 is where we start the poller.

The next code block is used to check the status of the current bulk shipment once it’s been sent for processing.

Some important lines to note here are:

  • Line 4, retrieves the current BulkJob status.
  • Line 21, if there are no validation errors we can send the shipments to be created.
  • Line 37, which sets where the user should get redirected to once all the shipments have been generated. In this instance we are sending the user directly to the printing page. Code below:

Now we get to the createQueuedShipmentRecord method and this is where we set the ServiceType, Packaging Type, Send from and Send to addresses.


Lastly, we call the validate and process bulk shipment methods that are referenced in the checkStatus method.


3. Finally, we tie it all together by creating the custom button on the Contacts list view to link to our new visualforce page.

We need to create a custom button on the contacts object. We do this by going to Setup > Customize > Contacts > Buttons, Links, and Actions and clicking on “New Button or Link


Complete the fields as you see here:


Next, add this button to your Contacts list view, which you can do by first going to Setup > Customize > Contacts > Search Layouts and editing the “Contacts List View” layout. Once this is done, move the bulk processing button you just created across to the “Selected buttons” section.


Continue reading »