Print this page

Impact on Apex code if "State and Country Picklists" feature is Enabled

Knowledge Article Number 000187734
Description
  • Requirement:  Intend to enable or activate the "State and Country Picklists" feature under the Data Management section.
Resolution
  • Developers need to append the word "code" to the picklist fields in their Apex Code, when the above feature is Enabled.
  • For instance, instead of using "mailingstate", developers will now have to use "mailingstatecode" to retrieve the old values in a trigger.

Code Example:
 
trigger MyContactTrigger on Contact (before update) {
   
   for (contact cContact : trigger.new) {                            
            Contact oldContact = trigger.oldMap.get(cContact.id);                            

            //Don't use mailingstate and mailingcountry to see the old values as shown below-
            string oldValues =   oldContact.AccountId + ' '+ oldContact.mailingstate+' '+oldContact.mailingcountry; 

            //following code will not display the old values. It will show the new values
            system.debug('oldValues: ' + oldValues);             
 
            //Instead use mailingstatecode and mailingcountrycode to see the old values as shown below- string oldValuesCodes = oldContact.AccountId + ' '+ oldContact.mailingstatecode +' '+ oldContact.mailingcountrycode;
            //following code will display the old values
            system.debug('oldValues using picklist codes: ' + oldValuesCodes);
    }

}




promote demote