Wednesday, May 18, 2011

Salesforce - Translate field values


Solution – We can make use of toLabel(object.field) method while querying that field and assign the value. This facilitates to copy the translated value to be copied instead of the master value.

    Sample Code: To retrieve the account records depending on the translated picklist value HeadQuarterCountry = Bengalooru and copy the translated value to some other field. 

            Account acc = [SELECT Id, Name, Region__c, toLabel(HeadQuarterCountry__c) from Account WHERE toLabel(HeadQuarterCountry__c) ='Bengalooru' limit 1;];
            acc.Region__c = acc.HeadQuarterCountry__c; // the value "Bengalooru" will be copied to region instead of master value "Bangalore"          

No comments:

Post a Comment