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
bretondevbretondev 

SOQL issue : How to get Shipping Country in my language?

Hello

We are using STate and Country piclists.
So on Contracts we have a ShippingAddress field that contains a ShippingCountry.

When I visualise a Swiss contract in our Salesforce UI, the ShippingCountry displays as "Suisse" ("Switzerland" in French).
Whiwh is normal because my personal language setting is set to French.

The issue is that when I query this contract with SOQL, the value of ShippingCountry is in English (Switzerland).

How can I get this ShippinCountry value in French when I query with SOQL?

I checked our company-wide settings, default language is also French.

Thanks
 
Contract c = [Select id , shippingcountry from contract where id = '8000Y000000FgEJQA0'];

system.debug('### MAB ' + c.ShippingCountry);

 
Best Answer chosen by bretondev
bretondevbretondev
I solved my issue with following code :
 
Schema.DescribeFieldResult countryCode = User.Countrycode.getDescribe();
        List<Schema.PicklistEntry> countryCodeEntries = countryCode.getPicklistValues();
        String country = '';
        if (String.isNotBlank(cont.ShippingCountryCode)) {
            for(Schema.PicklistEntry pe : countryCodeEntries){
                if (pe.getValue().equals(cont.ShippingCountryCode)) {
                   country = pe.getLabel();
                   break;
                }
            }
        }

 

All Answers

Akshay_DhimanAkshay_Dhiman
Hi Bretondev, 

 Here is a link of knowledge article. This is helpful for you. In that, all steps are well explained. follow these steps: 
 
https://help.salesforce.com/articleView?id=000005218&language=en_US&type=1
 
Thank You
Akshay
 
bretondevbretondev
That is not the issue.
I know how I can change my language and company language.
The question is how to get the ShippingCountry with French value when requestiong with SOQL.
As of now, when I perform here-above query, Apex returns "Switzerland" but I want "Suisse".
bretondevbretondev
I solved my issue with following code :
 
Schema.DescribeFieldResult countryCode = User.Countrycode.getDescribe();
        List<Schema.PicklistEntry> countryCodeEntries = countryCode.getPicklistValues();
        String country = '';
        if (String.isNotBlank(cont.ShippingCountryCode)) {
            for(Schema.PicklistEntry pe : countryCodeEntries){
                if (pe.getValue().equals(cont.ShippingCountryCode)) {
                   country = pe.getLabel();
                   break;
                }
            }
        }

 
This was selected as the best answer