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
Jake BackuesJake Backues 

how can i make an array of an array of objects in apex

My org has decided to use arrays over lists to reduce our overall code. We have a large amount of it. I have a SOSL query that returns and array of an array of SObjects. How can i use arrays instead of lists for the return value?

I get errors when doing this
SObject[][] searchList = [
            FIND :query IN ALL FIELDS RETURNING 
            Opportunity(Id, Name WHERE RecordType.Name In :recordTypeNames, 
            Service__c(Id, Name WHERE RecordType.Name In :recordTypeNames AND Status__c IN :serviceStatuses)
        ];

 
Gulafsha MohammedGulafsha Mohammed
Arrays and lists are same in salesforce except the syntax.
refer: https://www.tutorialspoint.com/apex/apex_arrays.htm
Here i attach a link to use sosl in salesforce: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_dynamic_sosl.htm
Please mark this as best answer if your problem is solved.
Jake BackuesJake Backues
Hi Gulafsha,

yes they are the same, and I understand how to use SOSL and Arrays individually. Can you show me an example of using arrays to capture the results of a SOSL Query? or the syntax of an array of an array. For example the list would be:
List<List<SObject>>()
But SObject[][] does not work. what is that syntax?
Gulafsha MohammedGulafsha Mohammed

The following example exercises a simple SOSL query string.
String searchquery='FIND\'Edge*\'IN ALL FIELDS RETURNING Account(id,name),Contact, Lead'; 
List<List<SObject>>searchList=search.query(searchquery);
Hope this has helped you.
Thanks,
Gulafsha
 
Jake BackuesJake Backues
Sorry Gulafsha, but you are not answering the question.

Please use arrays to accept the return value of the sosl query.