function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
James MersonJames Merson 

Apex class tests failing on picklist state and country

I have several apex class tests that are failing because we switched our state and country address fields to picklists.  I tried to correct it in the code but am still getting the same error:

System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, There's a problem with this country, even though it may appear correct. Please select a country from the list of valid countries.: [BillingCountry] 
Stack Trace: Class.Z_PaymentMethodCaptureControllerTest.createTestAccount: line 276, column 1 Class.Z_PaymentMethodCaptureControllerTest.testAppendMessages: line 185, column 1

When creating the account as part of the test, I code it to input United States, a value in our picklist field for BillingCountry.  

Tried to research answers but am coming up dry.  Any help out there?
Best Answer chosen by James Merson
Vinoth Vijaya BaskerVinoth Vijaya Basker
Hi James, 

Please try the below code,

BillingCountrycode = 'US';


Thanks,
Vinoth 

All Answers

ClintLeeClintLee
Try adding the BillingCountry as 'US' instead of 'United States'.  

When you use State and Country picklists the value will appear as 'United States' in the UI, but the actual value is 'US'.
James MersonJames Merson
Hi Billy,

That didn't work either unfortunately.  I got back the same error.  Any other thoughts?
Vinoth Vijaya BaskerVinoth Vijaya Basker
Hi James, 

Please try the below code,

BillingCountrycode = 'US';


Thanks,
Vinoth 
This was selected as the best answer
James MersonJames Merson
Hi Vinoth,

That was perfect.  Thank you sooooo much!

James