background

Zenkraft Blog

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

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: https://docs.zenkraft.com/usps/one-click-shipments

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:
https://zkusps.xxxx.visual.force.com/apex/Wizard?CF00NE0000003lPgf=00001026&CF00NE0000003lPgf_lkid=500E000000VCQyo&scontrolCaching=1&retURL=%2F500E000000VCQyo&sfdc.override=1

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:

https://zkusps.na39.visual.force.com/apex/Wizard

?CF00NE0000003lPgf=00001026
&CF00NE0000003lPgf_lkid=500E000000VCQyo
&scontrolCaching=1
&retURL=%2F500E000000VCQyo
&sfdc.override=1

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 »

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 »