function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Dev87Dev87 

Apex- Oreder by - Field cannot be sorted

Hello,
I tried to sort an object in Query Editor but I get this error: 
[object Object]: name from campaignmember ORDER BY Type_d_inscription__c ^ ERROR at Row:1:Column:65 field 'Type_d_inscription__c' can not be sorted in a query call

This is my query: 
select Type_d_inscription__c, name  from campaignmember ORDER BY Type_d_inscription__c

My Field is Multi-Select Filed type.
SandhyaSandhya (Salesforce Developers) 
Hi,

Refer to below statement in the salesforce developer document.

These data types are not supported: multi-select picklist, rich text area, long text area, encrypted (if enabled), and data category group reference (if Salesforce Knowledge is enabled).

https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_select_orderby.htm
 
Please mark it as solved if my reply was helpful, it will make it available
for others as a proper solution.

Best Regards,
​Sandhya
 
 
Shruti SShruti S
Unfortunately you cannot sort by a Multi picklist field. That being said, you can create a Formula Field with a return type of text with the below formula - 
SUBSTITUTE(
    IF(INCLUDES(Fruits__c, "Apple"),  "Apple,",  NULL) +
    IF(INCLUDES(Fruits__c, "Banana"), "Banana,", NULL) +
    IF(INCLUDES(Fruits__c, "Cherry"), "Cherry,", NULL) + ".",
    ",.",
    NULL
)
And you can then sort by this Formula Field like -
ORDER BY Formula_Field__c