We are using the Salesforce State/Country picklist and the integration values used for US States are state codes, e.g. CA, WY, AL, etc The salesforce AppExchange sends the leads to Salesforce and it always sends values as full State Names, e.g. California, Wyoming, etc. Because of which the leads fail to save in our database.

This is the error we receive while saving the lead when full state names are passed: There's a problem with this state, even though it may appear correct. Please select a state from the list of valid states.

Now, the workaround we thought to bypass this issue was to write a trigger that would set the state name to the state code if the passed in value was a state name and here is the trigger that I implemented:

trigger LeadStateMapping on Lead (before insert, before update) {
    System.debug(LoggingLevel.Info,'Executing trigger LeadStateMapping');
    for(Lead l : Trigger.new) {
        System.debug(LoggingLevel.Info,'LeadStateMapping > Lead: '+l);
        System.debug(LoggingLevel.Info,'LeadStateMapping > Lead > State: '+l.State);
        if(l.State == 'California') {
            l.State = 'CA';

But this doesn't seem to be working, although I don't get any errors in my debug logs, I still see the same error message as I see from the lead submission from AppExchange. Here are the debug logs that were printed:

USER_DEBUG|[2]|INFO|Executing trigger LeadStateMapping

USER_DEBUG|[4]|INFO|LeadStateMapping > Lead: Lead:{IsDeleted=false, FirstName=Peter, LastName=Jones, RecordTypeId=01240000000IVEHAA4, Company=Acme Bread, State=California, ......

USER_DEBUG|[5]|INFO|LeadStateMapping > Lead > State: California


If you check the last VARIABLE_ASSIGNMENT, it clearly shows that the state was converted to CA, but it still doesn't save as CA and throws an error. Any suggestions?

  • Do you have a default Country set? And what is the Country value on your record that is failing?
    – Jayant Das
    Dec 13, 2018 at 1:40
  • @JayantDas - Country passed is 'United States' and we do not have a default country set. Country isn't an issue because if I just change California to CA, the lead is inserted. So the issue is only with the State field. In fact, I did a debug print of the Lead object after modification by the trigger and it's exactly the same as the value if just CA is passed. Dec 14, 2018 at 3:38
  • It’s United States or US? State values do get impacted because of the Country value. It’s a bit confusing when you say you change the value to CA, it works, but that’s your issue, right that it’s not working?
    – Jayant Das
    Dec 14, 2018 at 4:07
  • US and United States both work for the Country value (even though the integration value for Country is set to US and not United States). But State only works when the value is CA. I just can't seem to figure this out. Dec 14, 2018 at 17:13

1 Answer 1


Seems like the code doesn't have any issues. It's a known Salesforce issue that the State cannot be modified using a before update/insert trigger if State Country picklist is enabled. Here's the Salesforce issue which is still open:


You must log in to answer this question.

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