I recently went through the process of updating my state and country fields to picklists using the standard Salesforce tools. Perhaps foolishly I completed this update directly in production. However this update--which forces a value for [Country] on new object creation (Lead, Account, etc.) has caused a number of errors in the Apex test classes in my org which didn't have a [Country] field because it wasn't required before this update. Normally I would just make edits to the test classes and call it good but most of the Apex in my org is in the form of managed packages which I can't edit. So now I'm in a position where my code coverage isn't high enough to import new code AND I can't edit the existing code to bring the code coverage above 75% because I don't have access to the managed packages. Any suggestions on where to go from here?

  • This tool would help is this exact situation (for the classes you can edit) and would not require you to update your test methods if you use its framework. Good app: appexchange.salesforce.com/…
    – Eric
    Commented Jan 14, 2015 at 17:09

2 Answers 2


Managed Package code coverage should not affect your own deployment of code in your org's namespace: Unit Test Code Coverage and Managed Packages

You should be able to bring your own code coverage up to above 75% without manage package test classes passing.

  • Hmmm...OK so then it must be in the code I can access. I only see two errors on classes from unmanaged packages, but that must be enough! Part of the problem still remains, i.e. how do I make the necessary changes to the Apex when I can't deploy those changes to production because the code coverage is too low. Seems like a catch-22? (since I can't simply "turn off" the picklist update I did). Commented Jan 14, 2015 at 15:21
  • You will need to create a sandbox and make the necessary changes there to get your code passing (only for your namespace). When you deploy from the sandbox to production, the deployment will only run the test classes in your namespace to verify the 75% coverage. Not sure if this answers your question. Commented Jan 14, 2015 at 15:23
  • 1
    Sorry, another clarification: the unmanaged package code is in your namespace, so you will have to analyze the unmanaged package code and update it to get it passing for code coverage. Only managed package code is excluded from the code coverage requirements. Commented Jan 14, 2015 at 15:26

It's tough to tell from your post why the tests are failing, but I assume it's because they're inserting state values without country values, going by this:

However this update--which forces a value for [Country] on new object creation (Lead, Account, etc.)

Country values are only required if you're also setting a state value. If the code causing errors is only using states from one country, one workaround would be to set the org's default country to that country.

If the tests are failing because they're inserting unrecognized state and country values into the text fields, you could also add those values to your state and country picklist configuration and uncheck the "visible" option. Invisible state and country picklist values are valid for API inserts, but do not appear in the end-user UI picklists.

I also want to clarify that turning on State and Country Picklists is reversible. You might have to undo updates to metadata like reports and formulas that use the picklists, but turning on State and Country Picklists is not a permanent change.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .