Hello friends, In this tutorial, we are going to learn about toLabel() function of salesforce. This function used in salesfoce SOQL and SOSL. In this section i am going to illustrate why we used this function in SOQL and SOSL and also shows some code example that shows clear picture of this function. So let's begin, 

toLabel() function in Salesforce

1. This function used to convert SOQL and SOQL results into the user's language.

2. If translation workbench is enabled, you can used this function to convert result into user's language.

3. This function will used in all salesforce editions.

4. For picklist and record type label we can use this function in SOQL and SOSL.

In SOQL:

 SELECT toLabel(object.field) FROM Sobject
In SOSL:
 FIND {Joe} RETURNING Lead(company, toLabel(Recordtype.Name))

5. This method can't be used with ORDER BY clause.

6. Queried results are return as per user language.

7. This function supports aliasing, Aliasing is required when SOQL and SOSL query includes the same field multiple time.

 FIND {John} RETURNING Account(Name, toLabel(Industry)AliasName)

8. This function used to filter record using a translated picklist value. For example, If user language set "spanish" comparison is made against the spanish value otherwise the comparison made against the real picklist value, if no translation is available.

Example:

 SELECT Name,toLabel(Industry) FROM Account

Output:

 

Hope you like this post, for any feedback or suggestions please feel free to comment. I would appreciate your feedback and suggestions.
Thank you.