+ Start a Discussion

Apex- Oreder by - Field cannot be sorted

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) 

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).

Please mark it as solved if my reply was helpful, it will make it available
for others as a proper solution.

Best Regards,
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 - 
    IF(INCLUDES(Fruits__c, "Apple"),  "Apple,",  NULL) +
    IF(INCLUDES(Fruits__c, "Banana"), "Banana,", NULL) +
    IF(INCLUDES(Fruits__c, "Cherry"), "Cherry,", NULL) + ".",
And you can then sort by this Formula Field like -
ORDER BY Formula_Field__c