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
HugoNowHugoNow 

Problem creating an Account with State & Country picklist activated

Hi,

I know this is beta but this might be a bug...or maybe just me.

 

I am trying to integrate with an external system and the information I have from the external system is the BillingCountry and the BillingStateCode. I do not have the BillingState from my external system, just the code. Therefore, I am trying to create an account using the folowing:

 

Account a = new Account(Name='TestHugo', BillingCountry='Canada', BillingStateCode = 'QC');
INSERT a;

 

However I get this error:
FIELD_INTEGRITY_EXCEPTION, A country must be specified before specifying a state value for field: [BillingStateCode]

Do you know if this is a bug or if I am just not using it the right way.

 

Any ideas?

Sujit NirkheSujit Nirkhe

Try This:

Account a = new Account(Name='TestHugo', BillingCountry='Canada', BillingState = 'QC');
INSERT a;

HugoNowHugoNow
Thanks for you response. I already tried it. Here is the error message when
I do as you suggest:

FIELD_INTEGRITY_EXCEPTION, There's a problem with this state, even though
it may appear correct. Please select a state from the list of valid
states.: [BillingState]

Hugo
melango ConsLeague.ax1827melango ConsLeague.ax1827

Does anyone have a solution for this?

I am getting the same error post WInter Release on Production when Apex code is run.

SwissQuebecSwissQuebec
You need to use BillingCountryCode, with the two-letter ISO code with the BillingStateCode.

If you can't use the BillingCountryCode, then you must use the solution from @Sujit Nirkhe. For me, it is working, but since you are using the BillingState with the ISO code value, there is a problem with the Integration value.

So for that to work, you must first go to Data Management - State and Country Picklists - Configure States and Countries - Canada and change for each Province the "Integration Value" from the full name to the ISO Code (ex. replace Quebec with QC). So the system will be able to understand QC sent through the BillingState and copy that to the BillingStateCode.
Rahul Gawale 26Rahul Gawale 26
I was able to solve this by just editing and saving records manually, which were causing the issue.
Some of the opportunities in our org, we were not able to close as
1. there was a process -> to update an account on closure,
2. there was a trigger to update contact roles.
So first I just "edit-save" the Account, then all OCRs. I was able to resolve the issue.