Problem with State/Province Code showing the wrong 'state' in a template field

  • 4
  • Problem
  • Updated 12 months ago
  • In Progress
We are using Salesforce's State and Country picklists.  When we display the State/Province Code in a separate column on a table component, the field shows the appropriate 'state' based on the selected country code and state/province code on the record.  When we display the State/Province Code in a template field, it pulls in the wrong 'state' for the selected country code and state/province code on the record.

In this example, you can see that we have set the state and country to be Pennsylvania and United States.



Viewing the same record in a template field, shows:

Note that 'Palermo' is a province in Italy.  It's State/Province Code is 'PA' and matches Pennsylvania's code.
Photo of Bill McCullough

Bill McCullough, Champion

  • 12,436 Points 10k badge 2x thumb

Posted 4 years ago

  • 4
Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,006 Points 20k badge 2x thumb
There are two sets of fields - for State and Country, there is a picklist field titled code and a text field. 

In my testing,  if you change the countryCode field to Italy,  the Normal State field will not update automatically while the State Code field will be updated to Palermo. 



So, make sure you are showing the same set of fields.  Either the code or the normal ones.   But not a mix... 
Photo of Rajesh Kumar

Rajesh Kumar

  • 738 Points 500 badge 2x thumb
Thanks Buddy ,
Photo of Bill McCullough

Bill McCullough, Champion

  • 12,436 Points 10k badge 2x thumb
Rajesh,

As a workardound, we added a Salesforce formula field to display the value from the StateCode field.  We use this in reference fields or template fields to display the correct 2 letter code instead of the rendered 'State Name' that shows the wrong state.

I think using a triple mustache should work to display the 2 letter code instead of the rendered name (e.g. {{{MailingStateCode}}}).

Thanks,

Bill
Photo of Rajesh Kumar

Rajesh Kumar

  • 738 Points 500 badge 2x thumb
Hi Bill ,

This is very easy to show state name according to Country Name  .We have used filed editor component in Skuid page ,

After is working fine , U can also use table .

Thanks,

Rajesh 
Photo of Bill McCullough

Bill McCullough, Champion

  • 12,436 Points 10k badge 2x thumb
Rob,

Thanks for your reply.  I was able to isolate what the issue seems to be.  It's not a problem with the template field.  It seems to be with using the Parent relationship to traverse the object data and pull in the State Code field from the Parent object.  In my first screenshot I was building a list view based on a junction object.  I was using the Parent relationship to pull in the State Code field.

I have created a list view based on the Contact object.  As you can see I can pull in the State Code field for the Contact object without issue.  When I use the Parent relationship to the Account object and pull in the State Code field, I get the results that I reported where the Shipping State Code on the parent Account to the Contact object shows as a 'state/province' for another country.



I have attached the xml for my page so you can install it in your org.  Let me know if you need more details.

Thanks,

Bill

<skuidpage unsavedchangeswarning="yes" showsidebar="true" showheader="true" tabtooverride="Contact">
<models>
<model id="Contact" limit="100" query="true" createrowifnonefound="false" sobject="Contact">
<fields>
<field id="FirstName"/>
<field id="LastName"/>
<field id="CreatedDate"/>
<field id="MailingCity"/>
<field id="MailingCountryCode"/>
<field id="MailingStateCode"/>
<field id="MailingStreet"/>
<field id="AccountId"/>
<field id="Account.Name"/>
<field id="Mailing_Zip_Code_Lookup__r.Name"/>
<field id="Account.ShippingCountryCode"/>
<field id="Account.ShippingStateCode"/>
</fields>
<conditions/>
<actions/>
</model>
</models>
<components>
<pagetitle model="Contact">
<maintitle>
<template>{{Model.labelPlural}}</template>
</maintitle>
<subtitle>
<template>Home</template>
</subtitle>
<actions>
<action type="savecancel"/>
</actions>
</pagetitle>
<skootable showconditions="true" showsavecancel="false" searchmethod="server" searchbox="true" showexportbuttons="false" pagesize="10" createrecords="true" model="Contact" mode="read">
<fields>
<field id="FirstName" allowordering="true"/>
<field id="LastName" allowordering="true"/>
<field id="AccountId"/>
<field id="Account.ShippingStateCode"/>
<field id="Account.ShippingCountryCode"/>
<field type="COMBO" valuehalign="">
<label>Account Template Field</label>
<template>{{Account.ShippingStateCode}} {{Account.ShippingCountryCode}}</template>
</field>
<field id="MailingStateCode" valuehalign="" type=""/>
<field id="MailingCountryCode"/>
<field type="COMBO" valuehalign="">
<label>Contact Template Field</label>
<template>{{MailingStreet}}, {{MailingCity}}, {{MailingStateCode}} {{Mailing_Zip_Code_Lookup__r.Name}} {{MailingCountryCode}}</template>
</field>
</fields>
<rowactions>
<action type="edit"/>
<action type="delete"/>
</rowactions>
<massactions usefirstitemasdefault="true">
<action type="massupdate"/>
<action type="massdelete"/>
</massactions>
<views>
<view type="standard"/>
</views>
</skootable>
</components>
<resources>
<labels/>
<css/>
<javascript/>
</resources>
</skuidpage>

Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,006 Points 20k badge 2x thumb
Thanks for the XML.  In the org where we have state / country picklist values implemented I get the results I would expect and its hard to get a record to save with a bad state code.    Would you mind showing me what the account detail page for Kennedy Health Alliance looks like?  (with both the regular values and the state values)   I'm still not convinced there isn't a mismatch in that record. 
Photo of Bill McCullough

Bill McCullough, Champion

  • 12,436 Points 10k badge 2x thumb
Rob...I created simple pages for the Account record--both a list view and detail view.   They show the Account record with the correct data.  Here are the screenshots:




I also did  an SOQL query using Workbench.  It shows the right StateCode and CountryCode for Kennedy Health Alliance.
Photo of Bill McCullough

Bill McCullough, Champion

  • 12,436 Points 10k badge 2x thumb
Rob...I was able to reproduce the problem I am seeing in a Developer Org. where I just installed Skuid and just enabled the State and Country picklists.  I used the same page that I sent to you in an earlier thread. In this screenshot, the State Province code should show as California.

Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,006 Points 20k badge 2x thumb
Tomorrow I'll spin up a new Dev Org.  The org I was in was a little old....  We'll keep trying to figure this out. 
Photo of Bill McCullough

Bill McCullough, Champion

  • 12,436 Points 10k badge 2x thumb
Rob...any update on this issue?
Photo of Bill McCullough

Bill McCullough, Champion

  • 12,436 Points 10k badge 2x thumb
Rob,

We still have a problem with the State/Province code not showing the right value in Template fields.  We were able to work around this issue with some of our users. We now have a situation where we can't use the work around.

Would you you look into this.

Thanks,

Bill
Photo of Karen Waldschmitt

Karen Waldschmitt, Official Rep

  • 8,260 Points 5k badge 2x thumb
Hi Bill~

I believe the problem is actually stemming from how Salesforce handles the data. When you use the state/country picklist, the states are dependent on the country. When you change the country, your options for the states also change. Unfortunately, when there is a state in the new country that has the same state code, it will automatically change to that state. See my example below.
 
Here is the correct state info based on a country selection of the U.S. 


However, when I change the country to Italy, notice that 2 things happen.
  • The billing state gets overriden to None because there isn't a state in Italy that has TX as its state code. 
  • The shipping state changed to Palermo because Palermo has the same state code as Pennsylvania.


This faulty data, then, gets passed into your Skuid page as well. We will open up a case with Salesforce about this issue and let you know what we find out.  

Hope this clarifies the problem. 

Thanks!
Karen
Photo of Bill McCullough

Bill McCullough, Champion

  • 12,436 Points 10k badge 2x thumb
Karen,

Thanks for looking into this.  This does seem to be strange behavior in Salesforce. 

I am not sure that this is the cause of the issue I see in Skuid.  Here is a Skuid page from my developer org. that shows what I am seeing.

I have a list of Contact records and I am showing fields from the 'parent' Account record.  I also added a drawer to show the data from the Account.  You can see that the state and country are correctly set.  The data in the table incorrectly shows the state as 'Cagliari' instead of 'California'.  This seems more like a display issue for Skuid.



<skuidpage unsavedchangeswarning="yes" showsidebar="false" showheader="true" tabtooverride="Contact" personalizationmode="server">    <models>
        <model id="Contact" limit="100" query="true" createrowifnonefound="false" sobject="Contact" adapter="salesforce" service="salesforce" type="">
            <fields>
                <field id="FirstName"/>
                <field id="LastName"/>
                <field id="CreatedDate"/>
                <field id="MailingCity"/>
                <field id="MailingCountryCode"/>
                <field id="MailingStateCode"/>
                <field id="MailingStreet"/>
                <field id="AccountId"/>
                <field id="Account.Name"/>
                <field id="Account.ShippingCountryCode"/>
                <field id="Account.ShippingStateCode"/>
                <field id="Account.Id"/>
            </fields>
            <conditions/>
            <actions/>
        </model>
        <model id="AccountDrawer" limit="20" query="false" createrowifnonefound="false" adapter="salesforce" service="salesforce" type="" sobject="Account">
            <fields>
                <field id="Name"/>
                <field id="Id"/>
                <field id="ShippingCountry"/>
                <field id="ShippingCountryCode"/>
                <field id="ShippingState"/>
                <field id="ShippingStateCode"/>
                <field id="ShippingStreet"/>
                <field id="ShippingPostalCode"/>
                <field id="ShippingCity"/>
            </fields>
            <conditions>
                <condition type="fieldvalue" value="" enclosevalueinquotes="true" field="Id" state="filterableoff" inactive="true" name="AccountIdDrawer"/>
            </conditions>
            <actions/>
        </model>
    </models>
    <components>
        <pagetitle model="Contact" uniqueid="sk-2qqdCo-87">
            <maintitle>
                <template>{{Model.labelPlural}}</template>
            </maintitle>
            <subtitle>
                <template>Home</template>
            </subtitle>
            <actions>
                <action type="savecancel"/>
            </actions>
        </pagetitle>
        <skootable showconditions="true" showsavecancel="false" searchmethod="server" searchbox="true" showexportbuttons="false" pagesize="10" createrecords="true" model="Contact" mode="read" uniqueid="sk-2qqdCo-88">
            <fields>
                <field id="FirstName" allowordering="true"/>
                <field id="LastName" allowordering="true"/>
                <field id="AccountId"/>
                <field id="Account.ShippingStateCode" valuehalign="" type="">
                    <label>State Code from Account</label>
                </field>
                <field id="Account.ShippingCountryCode" valuehalign="" type="">
                    <label>Country Code from Account</label>
                </field>
                <field type="COMBO" valuehalign="">
                    <label>Account Address Template Field</label>
                    <template>{{Account.ShippingStateCode}} {{Account.ShippingCountryCode}}</template>
                </field>
                <field id="MailingStateCode" valuehalign="" type="">
                    <label>Contact State Code</label>
                </field>
                <field id="MailingCountryCode" valuehalign="" type="">
                    <label>Contact Cournry Code</label>
                </field>
                <field type="COMBO" valuehalign="">
                    <label>Contact  Address Template Field</label>
                    <template>{{MailingStreet}}, {{MailingCity}}, {{MailingStateCode}} {{Mailing_Zip_Code_Lookup__r.Name}} {{MailingCountryCode}}</template>
                </field>
            </fields>
            <rowactions>
                <action type="edit"/>
                <action type="delete"/>
                <action type="drawer" label="Run multiple actions" icon="sk-icon-account-profile" openicon="fa-long-arrow-up">
                    <drawer title="Drawer Area" width="90%" closehandle="true">
                        <components>
                            <basicfieldeditor showheader="true" showsavecancel="true" showerrorsinline="true" model="AccountDrawer" buttonposition="" uniqueid="sk-2qxxd6-204" mode="read">
                                <columns>
                                    <column width="50%">
                                        <sections>
                                            <section title="Section A" collapsible="no">
                                                <fields>
                                                    <field id="Name" valuehalign="" type=""/>
                                                    <field id="ShippingCity"/>
                                                    <field id="ShippingCountry"/>
                                                    <field id="ShippingCountryCode"/>
                                                    <field id="ShippingState"/>
                                                    <field id="ShippingStateCode"/>
                                                    <field id="ShippingStreet"/>
                                                    <field id="ShippingPostalCode"/>
                                                </fields>
                                            </section>
                                        </sections>
                                    </column>
                                    <column width="50%">
                                        <sections>
                                            <section title="Section B" collapsible="no">
                                                <fields/>
                                            </section>
                                        </sections>
                                    </column>
                                </columns>
                                <conditions/>
                            </basicfieldeditor>
                        </components>
                        <beforeload>
                            <action type="setCondition" model="AccountDrawer" condition="AccountIdDrawer" value="{{AccountId}}"/>
                            <action type="requeryModel" model="AccountDrawer" behavior="loadmore"/>
                        </beforeload>
                    </drawer>
                </action>
            </rowactions>
            <massactions usefirstitemasdefault="true">
                <action type="massupdate"/>
                <action type="massdelete"/>
            </massactions>
            <views>
                <view type="standard"/>
            </views>
        </skootable>
    </components>
    <resources>
        <labels/>
        <css/>
        <javascript/>
    </resources>
    <styles>
        <styleitem type="background" bgtype="none"/>
    </styles>
</skuidpage>
Photo of Paul

Paul

  • 442 Points 250 badge 2x thumb
Any feedback on this?  Same problem here, looking up country code on parent account and getting the wrong interpretation, is correct in the db...
Photo of Bill McCullough

Bill McCullough, Champion

  • 12,436 Points 10k badge 2x thumb
Paul,

I still see the problem in 10.0.4.  If you show the CountryCode field from the parent account as a template field and use a triple mustache, you will get the 2 letter code for the country (i.e. {{{ShippingCountryCode}}}).  If you need the country name, I'd suggest a Salesforce formula field.

Skuid,

Any update on this?  Is it in the queue for a fix?

Thanks,

Bill
Photo of Eulogio Gallo

Eulogio Gallo

  • 1,874 Points 1k badge 2x thumb
I just recently started experiencing this issue. Any news on this?