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
ManojKumar MuthuManojKumar Muthu 

Illegal conversion from List<List<Case>> to List<Case>

Hi,

I am trying to query across all field with an object(case), just like the search bar so that whatever keyword I enter it should query all field and throw back list of record that matach the keyword,
below the code I use,
@RestResource(urlMapping='/Casequery/*')
global with sharing class CaseQuery {
    
    @HttpGet
    global static List<Case> getCase() {
       RestRequest req = RestContext.request;
        RestResponse res = RestContext.response;
        String Id = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);
        List<List<Case>> results = [FIND 'map*' IN ALL FIELDS RETURNING Case (id, Call_Back_Type__c, IsEscalated, 
                                                                             Case_Owner_Name__c, OwneEmail__c, subject, Case_Type__c, 
                                                                             Code__c, Tracker__c, status, Version__c, type, priority, ContactEmail,
                                                                             ContactId, OwnerId, CaseNumber)];
                                                                             return results;
}
}

and geting an error:Illegal conversion from List<List<Case>> to List<Case>

Any thought on this??



 
Best Answer chosen by ManojKumar Muthu
Khan AnasKhan Anas (Salesforce Developers) 
Hi Manoj,

Greetings to you!

In your code, you are using List<Case> as return type but the SOSL always return the List of List of sobjects like List<List<Case>> 

If you will change the return type to List<List<Case>>  in your code that will work.

global static List<List<Case>> getCase() { ... }

Try below code:
 
@RestResource(urlMapping='/Casequery/*')
global with sharing class CaseQuery {
    
    @HttpGet
    global static List<List<Case>> getCase() {
        RestRequest req = RestContext.request;
        RestResponse res = RestContext.response;
        String Id = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);
        List<List<Case>> results = [FIND 'map*' IN ALL FIELDS RETURNING Case (id, Call_Back_Type__c, IsEscalated, 
                                                                              Case_Owner_Name__c, OwneEmail__c, subject, Case_Type__c, 
                                                                              Code__c, Tracker__c, status, Version__c, type, priority, ContactEmail,
                                                                              ContactId, OwnerId, CaseNumber)];
        return results;
    }
}

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas

All Answers

Khan AnasKhan Anas (Salesforce Developers) 
Hi Manoj,

Greetings to you!

In your code, you are using List<Case> as return type but the SOSL always return the List of List of sobjects like List<List<Case>> 

If you will change the return type to List<List<Case>>  in your code that will work.

global static List<List<Case>> getCase() { ... }

Try below code:
 
@RestResource(urlMapping='/Casequery/*')
global with sharing class CaseQuery {
    
    @HttpGet
    global static List<List<Case>> getCase() {
        RestRequest req = RestContext.request;
        RestResponse res = RestContext.response;
        String Id = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);
        List<List<Case>> results = [FIND 'map*' IN ALL FIELDS RETURNING Case (id, Call_Back_Type__c, IsEscalated, 
                                                                              Case_Owner_Name__c, OwneEmail__c, subject, Case_Type__c, 
                                                                              Code__c, Tracker__c, status, Version__c, type, priority, ContactEmail,
                                                                              ContactId, OwnerId, CaseNumber)];
        return results;
    }
}

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas
This was selected as the best answer
ManojKumar MuthuManojKumar Muthu
Hi Khan Anas,

Thanks for the timely help,

Yeah its works fine now, by the way I am trying to create a search bar just mentioned above, where I enter a keywords and query will list of all the records mataching that keyword. Is there a way to achive this?
 
Raj VakatiRaj Vakati
Try this code 
 
@RestResource(urlMapping='/Casequery/*')
global with sharing class CaseQuery {
    
    @HttpGet
    global static List<List<Case>> getCase() {
       RestRequest req = RestContext.request;
        RestResponse res = RestContext.response;
        String Id = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);
        List<List<Case>> results = [FIND 'map*' IN ALL FIELDS RETURNING Case (id, Call_Back_Type__c, IsEscalated, 
                                                                             Case_Owner_Name__c, OwneEmail__c, subject, Case_Type__c, 
                                                                             Code__c, Tracker__c, status, Version__c, type, priority, ContactEmail,
                                                                             ContactId, OwnerId, CaseNumber)];
                                                                             return results;
}
}