Wednesday, 10 April 2019

Translating Results for SOQL


Use toLabel(fields) to translate SOQL query results into the user’s language.
A client application can have results from a query returned that are translated into the user’s language, using toLabel():
1toLabel(object.field)
Any organization can use toLabel(). It is particularly useful for organizations that have the Translation Workbench enabled. Use toLabel() to return translations on:
  • Regular, multi-select, division, or currency code picklist fields that have values returned by the relevant describe call.
  • Data category group and data category unique name fields.
  • RecordType names.
Note
Object history is supported on a limited basis. When a tracked field changes, SELECT toLabel(Field) FROM *History returns either the changed field’s master label or the translated label, if one exists. OldValue and NewValue fields in field history objects also support toLabel, but only tracked changes on supported field types return translated values.
For example:
1SELECT Company, toLabel(Recordtype.Name) FROM Lead
This query returns lead records with the record type name translated into the language for the user who issued the query.
Note
You can’t filter on the translated name value from a record type. Always filter on the master value or the ID of the object for record types.
You can use toLabel() to filter records using a translated picklist value. For example:
1SELECT Company, toLabel(Status)
2FROM Lead
3WHERE toLabel(Status) = 'le Draft'
Lead records are returned where the picklist value for Status is 'le Draft.' The comparison is made against the value for the user’s language. If no translation is available for the user’s language for the specified picklist, the comparison is made against the master values.
Note
The toLabel() method can’t be used with ORDER BY. Salesforce always uses the picklist’s defined order, just like reports. Also, you can’t use toLabel() in the WHERE clause for division or currency ISO code picklists.

No comments:

Post a Comment