Syntax Highlighter JS

Wednesday, February 20, 2013

Update: VF component for USPS address verification

Back in October I posted a Visual Force component that would contact the USPS (using your free account) to verify your address and give you a chance to correct or standardize it.  This can be very handy when using Visual Force pages to enter leads into your system.

A few people commented that they could get this working in the test / sandbox system but that it would fail deployment to production with an  System.CalloutException of "You have uncommitted work pending. Please commit or rollback before calling out".

This was very interesting because even the classes that were not making any DML statements (insert, update, etc) were causing this error to be thrown.   I wasn't the only one who ran into this error as you can read about in this thread on the developer boards.

Salesforce has now fixed the deployment tool such that if you wrap the test methods (that use the mock functionality) with Test.StartTest() and Test.StopTest() you can now deploy to production directly.  

Previously you had to use a complex scheme where you would rename the classes such that the mock callout classes were alphabetically first.

I have updated the source code on Git Hub and you can get it here.  You should be able to directly deploy this to production with 100% code coverage.