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:
- As this component contains its own form, you cannot place it inside of another form.
- 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.
- 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.
- 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.
- 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.
<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.
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.
ReplyDeleteI 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?
Thanks
David
Never mind - I just found out this is a known issue:
ReplyDeletehttps://sites.secure.force.com/success/ideaView?id=08730000000jcfAAAQ
http://salesforce.stackexchange.com/questions/3486/testing-httpcallout-with-httpcalloutmock-and-unittest-created-data
Yes, I have run into this error. In the Winter 13 build, this error can occur for many different reasons.
ReplyDeleteHere 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.
Anyone who is reading this should be aware that updated code has been posted. Please read my post about this here.
ReplyDeleteTotal noob here asking for help. I am trying to make this work, but I get the following error:
ReplyDeletejava.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.
I get that error while trying to make the test page to work.
ReplyDeleteNever mind, I found the error and it's working now. Thanks for posting this. :)
ReplyDelete