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.


  1. Hello Coleman. Thanks for posting this. I am trying out your HttpMock class and I'm wondering if you ever ran into "uncommitted work pending" error during unit testing.

    I have an afterinsert trigger calling a future method which calls another method that does the callout, and then the future method updates the record that was inserted.

    I'm getting "uncommitted work pending" errors in the unit test. However, the trigger/future method calls work fine in the user interface - I can create a new record manually, and a few seconds later I get updated results from the callout.

    If you did get "uncommitted work pending" errors, do you remember what the solution was?


  2. Never mind - I just found out this is a known issue:

  3. Yes, I have run into this error. In the Winter 13 build, this error can occur for many different reasons.

    Here is a good thread that talks about this issue:

    In my case, the class it self had no DML and was only updating variables in memory but hit this error due to an issue with the way the deployment tool tests the classes (See the thread for details).

    If you need to promote some code before that gets fixed and/or you are doing DML, then you might want to abandon the mock HTTP call out for now.Here is a link to an older and more complex method of getting higher code coverage on callouts w/o the mock class.

  4. Anyone who is reading this should be aware that updated code has been posted. Please read my post about this here.

  5. Total noob here asking for help. I am trying to make this work, but I get the following error:

    java.lang.IllegalArgumentException: Illegal view ID USPSUserIDCode = myuspsIDishere; return null;. The ID must begin with /

    I don't know what I am doing wrong. Any information would be much appreciated.

  6. I get that error while trying to make the test page to work.

  7. Never mind, I found the error and it's working now. Thanks for posting this. :)