0

Use Case I have a custom address field on a custom object and I want it to be prefilled with the Shipping of an Account that is a Lookup on the custom object. State and Country/Territory Picklists is configured to allow the state Niederlande and a few other states. enter image description here

My Approach In a record triggered flow (before create) I assign the values from Shipping Address of the Account to the custom address field on the custom object: enter image description here

My Problem When debugging, everything works fine. But when running in system with the flow activated I receive the following error message:

Pickup Address (Country/Territory): bad value for restricted picklist field: Niederlande

Trying with Apex I tried to set the value using Apex and retrieved the same error. Even the following lines failed:

List<PicklistEntry> picklistEntries = Agreement__c.Pickup_Address__CountryCode__s.getDescribe().getPicklistValues();
    agreement.Pickup_Address__CountryCode__s = picklistEntries.get(0).getLabel();
    insert agreement;

How can I assign the Shipping Address of the Account to the custom Address field on the Custom Object?

2
  • Do you have record types enabled for this object? if so, check in the record type that the value is included for the picklis.
    – Json
    Commented Feb 11, 2023 at 21:59
  • Since you answered your question I suggest you accept your own answer to mark the question as solved.
    – gvgramazio
    Commented Feb 12, 2023 at 15:03

1 Answer 1

1

The answer is quite easy, but somehow I missed it when testing. I used the label of the picklist entry, but I should have used the value.

To stay in the example mentioned in the question: 'Niederlande' is the label of the picklist entry for the custom address field country/territory. The value of the picklist entry is 'NL'. The lines of Apex code are also wrong since it should be

List<PicklistEntry> picklistEntries = Agreement__c.Pickup_Address__CountryCode__s.getDescribe().getPicklistValues();
agreement.Pickup_Address__CountryCode__s = picklistEntries.get(0).getValue();  // Note getValue() instead of getLabel()!
insert agreement;

How I solved it in the end:

  1. Configure States and Country/Territory Picklists
  2. Enable them also for Standard Address fields (this also includes mapping existing data)
  3. Step back to the flow and assign CustomAddressField.CountryCode the value of ShippingAddress.CountryCode

Steps 1 and 2 are a huge amount of work if you have multiple countries with multiple states.

You must log in to answer this question.

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