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
BritishBoyinDCBritishBoyinDC 

Migrating a JavaScript array to APEX

I have a s-control that I would like to convert into APEX/VF. The current s-control executes two queries  - one from both the Event Object, and the other from a Custom Object. I then create an array which I populate with the results of both queries, sort by a date field in the array, and then display to the users a single list of data, ordered by date ascending.

 

Reading through the docs, I can't see how to replicate that functionality. It seems like it should be some form of List but as far as I can see, they are all one dimension unless they arebased on a sObject. Can someone suggest where I should start in creating a array that I can populate with the results of the two queries?

 

Thanks 

Best Answer chosen by Admin (Salesforce Developers) 
SovaneSovane

Of course, you can do a list of list for example.

Message Edited by Sovane on 02-03-2009 12:26 AM

All Answers

SovaneSovane
Hi BritishBoyinDC,

Try to adapt the following concept to your requirements,

**APEX**
List<String>listReturn=new List<String>();
Event[] myEvents=[SELECT aString__c FROM Event];
myObject[] myObjects=[SELECT aString__c FROM myObjects];
for(Event myEvent:myEvents)listReturn.add(myEvent.aString__c);
for(myObject myObject:myObjects)listReturn.add(myObject.aString__c);
listReturn.sort();
Message Edited by Sovane on 02-03-2009 12:26 AM
BritishBoyinDCBritishBoyinDC

Thanks.

 

The one bit I am still ensure on is that the queries I return have multiple columns, whereas my understanding of the List<String> object is that it is only one string element per row in the array - or is there a way that this contruct can store multi elements per row returned from the query?

SovaneSovane

Of course, you can do a list of list for example.

Message Edited by Sovane on 02-03-2009 12:26 AM
This was selected as the best answer