Newer Version Available

This content describes an older version of this product. View Latest

Translate Returned SOQL Results

To translate SOQL query results into the language of the user who submits the query, use the toLabel method.

Any organization can use the toLabel() method. It’s particularly useful for organizations that enabled the Translation Workbench.

The toLabel method uses the following syntax:

1toLabel(object.field)
Use this method to return translated search results on:
  • Regular, multiselect, division, or currency code picklist fields, whose values are returned by the relevant describe API call.
  • Data category group and data category unique name fields.
  • Recordtype names.
  • Object History. HISTORY is supported on a limited basis. When a tracked field changes, the clause SELECT toLabel(Field) FROM *History returns the primary label of the changed field or the existing translated label. OldValue and NewValue fields in history objects also support the toLabel method, but the query returns translated values for only tracked changes on supported field types.

For example:

1SELECT Company, toLabel(Recordtype.Name) FROM Lead

The returned records are translated into the language of the user who issued the query.

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.

Note

You can use the toLabel() method to filter records using a translated picklist value. For example:

1SELECT Company, toLabel(Status)
2FROM Lead
3WHERE toLabel(Status) = 'le Draft'

The query returns lead records with a picklist value for Status equal to 'le Draft.' The comparison is made against the value for the user’s language. If no translation is available for the picklist, the comparison is made against the master values.

The following limitations apply to translated picklist values:
  • The LIKE operator can only query on the label of the picklist, not on its API name.
  • You can’t use the toLabel() method with the operator ORDER BY. SOQL always uses the picklist’s defined order.
  • You can’t use the toLabel()method in a WHERE clause for division or currency ISO code picklists.