background

Zenkraft Blog

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

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 »

Request FedEx rate for shipment from the Account Object

Published on 28 March 2017 by in  

Today we will show you how you can get FedEx rates for a shipment and add the users choice back onto the account object.

The first thing we need to do is set the “to” and “from” address of the shipment. In the code below we get the preference details to ship from and we get the ship to address details from the account object itself. We add all this information to a queuedShipment object.

Note lines 40-43 where the Packaging Type, Unit Dimensions, DropOff Type and Service Type are set.

The next step is to create the FedEx package type to include the Declared Value and the Weight. This can be done using this code here:

If you need to add special services then create the QueuedShipmentSpecialServices object like so:

We now have the required information to create a successful rate request. Which is done using this line of code:

The ratesList variable contains all the rate information that is returned from FedEx. Each record in this list is of type zkfedex.ShipmentRate, and the information contained is:

If you want the user to select the rate to write back to the Account object field Fedex_Quote__c you can use ratesList in apex:pageBlockTable. Make sure to add apex:commandLink in the first apex:column to get cost and set it to the field in record.

accountRecord.Fedex_Quote__c = selectedRate.cost;

Fedex_Quote__c is the field where you want to store FedEx quote and selectedRate is the line that was selected by the user on the VisualForce page.

Any questions please contact us. Happy coding.

Continue reading »

Add External UPS tracking numbers to an Order

Published on 14 March 2017 by in salesforce tracking 

In today's blog post we’ll show you how to add externally created UPS tracking number to an object. Most common use cases are to get updated tracking, that you are then able to query using the standard Salesforce reporting. We will be using the Order object in our demo here.

 

Trigger on the Order Object:

Line 3: For when a brand new order is added with a tracking number

Line 6: For when the tracking number field is updated

 

The trigger Handler class:

This is where the work gets done.

Line 4: 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 7-11: 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.

Shipping Settings

Line 27-39: For any new Orders, create the new shipment with the zkups__MasterTrackingId__c and make sure its linked to your UPS Preference via the zkups__UPSShipmatePreference__c.

Line 40-63: If you are just updating the tracking number field (FB_Tracking_Numbers__c) on your Order, this lines take care of the shipment creation.

Line 67-69: If a shipment has been queued for insertion, then we insert the Shipments.

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 »

Create a FedEx shipment from a trigger on the Account object

Published on 08 March 2017 by in salesforce fedex 

Today’s blog post explains how to create a FedEx shipment directly from a trigger on a standard Salesforce Account object. You will need our FedEx app and our Bulk Shipping package (sandbox install link, production install link, please be aware there are extra licensing costs for using the bulk package.) Contact us if you need any further information.

 

Firstly, create a checkbox on your account object. Let’s call it Create_Fedex__c. We will run the shipment creation process when this gets set to TRUE.

To store any validation errors (such as incorrect addresses), you need to create a custom object called Zenkraft_Validation_Error__c. Fill in the fields as you see here:

Custom Object Zenkraft Validation Error Salesforce Enterprise Edition

Next, create the trigger on the Account object. You can see the code below:

 

 

The trigger calls the AccountTriggerHandler that determines whether the checkbox has been set to TRUE, and if so, creates the shipment.

Lines 13-20: Get the address information from the account object that is needed to create the shipment.

Lines 25-33: Create the queued shipment.

Lines 35-43: Create the package, including the weight and declared value.

Lines 45-47: If the above have been generated successfully we use the processShipments method to start the creation process

 

 

FedexShipmentService is the class that allows the easy creation of the QueuedShipments, it gets the account details from the FedEx account that you have set up, and creates the BulkShipment where we store all the shipment information before we actually send it to be processed.

Lines 6-41: We set the zkfedex__ServiceType__c , zkfedex__PackagingType__c for the shipment along with the sender and recipient addresses.

 

 

To handle any errors, create another trigger. This time put it on the Queued Shipment Status object.

 

 

And the respective trigger handler code is below:

 

 

Happy coding.

Continue reading »