Syntax Highlighter JS

Monday, October 1, 2012

VF component for USPS address verification of leads

Previously, I posted an example class for accessing the USPS's e-commerce API to validate addresses for free.   I have updated that logic and created a component for easy use.   The code has been posted to github and can be found here.

Since the code has decent comments and is available above, this post will focus on an example of how to use the component in a page.

Please note that you will need an account with the USPS for this to work.  Please see my previous post for links to create the account and the user guide. 

Usage Notes:
  1. As this component contains its own form, you cannot place it inside of another form.
  2. Due to a lack of an action method on components, you will trigger the lookup by passing a valid USPS User code and reloading the page - when you are ready for the pop-up.
  3. This component uses the new mock HTTP response class and as such you won't be able to use it without Winter 13 of Salesforce.
  4. JQuery, JQuery UI (with lightness css), and JQuery Block UI are all used by this component but are loaded from CDN's.  Please see the read me file for details.
  5. This component is designed to be used on the Lead object only and for the standard address fields.  You will need to customize it for use with any other object and/or fields.
 In your page, you can reference your component (outside of a form) like this:

<c:USPS_Address LeadObject="{!CurrentLead}" CheckFullZip="true" USPS_USERID="{!USPSUserIDCode}" /> In your page controller, declare the variable and default it to a blank string: public string USPSUserIDCode {get; set;} public TestController() { USPSUserIDCode = ''; } // TestController
Then in your page controllers action function, you will need some logic like this to trigger the lookup:
USPSUserIDCode = 'INSERTYOURIDHERE'; return null; The method should be a page refrerence return type. When the variable is set and the page gets re-rendered, the pop-up will appear and look something like this:

Note that the rest of the page will be blocked until the pop-up dialog has been addressed.