I am using the toLabel function in an aggregate query, but it doesn't return the translation of the picklist value.

I have changed the language of the user to Dutch and executed the following query:

SELECT toLabel(Equipment__r.technical_Platform__c) 
FROM Maintenance_Schedule__c 
GROUP BY Equipment__r.technical_Platform__c 

The query returns the English value: Other Elevator likes

When I remove the GROUP BY from the query, it returns the translated value:

SELECT toLabel(Equipment__r.technical_Platform__c) 
FROM Maintenance_Schedule__c

Result with the Dutch value: Overige

I am not able to add the toLabel function in the GROUP BY, since only date aggregate functions are allowed as grouping expressions. I checked the documentation of the toLabel function, but it doesn't mention anything about grouping expressions. Documentation

I also found a topic about the same issue on the developer forums of Salesforce, but it didn't get any replies and it is from 2012. Topic

I could execute a 2nd query without the GROUP BY to get the translated values and map it to results of the results of the query with the GROUP BY, but I am wondering if there is a better solution?

  • That looks like a bug to me - I'd file a case with Salesforce Support ... – user735 Jan 19 '15 at 23:26

SELECT toLabel(Equipment__r.technical_Platform__c) aliasTECPROB FROM Maintenance_Schedule__c GROUP BY Equipment__r.technical_Platform__c

Use Alias it will work out

| improve this answer | |
  • Really strange but indeed this is working.. Additionally, the results don't show at all if I run the query in Developer Console Query Editor. However if I run in Execute Anonymous they are displayed fine (grouped and translated) in the debug logs. – Guy Clairbois Jul 10 '18 at 11:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.