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
dgindydgindy 

Combining results

Is it possible to Union the SOSQL statement before returning it to the VF page? 
 
Code:
t1=[Select WhatId,Name__c,Description,ActivityDate,ActivityDateTime,Id,OwnerId,TimeConverted__c,RelatedName__c,Owner.Name from Event  where Type='In-Service'  and (ActivityDate = THIS_MONTH or ActivityDate = NEXT_WEEK)  and (Owner.UserRole.ParentRoleId=:GroupId or ownerid=:Userid)];
t2=[Select WhatId,Name__c,Description,ActivityDate,ActivityDateTime,Id,OwnerId,TimeConverted__c,RelatedName__c,Owner.Name from Event  where Type='In-Service'  and (ActivityDate =LAST_N_DAYS:30) and Status__c='Completed'  and (Owner.UserRole.ParentRoleId=:GroupId or ownerid=:Userid)];

[Union T1 T2]—–˜™

 ???
 
I have two seperate searchs i wish to return and display. 
 
Thanks
Drew1815Drew1815
I think you have two options.
1) For efficiency, you could combine those two queries into one. You would just need to make small modifications to the Where clause.
2) If you keep the queries separate, then you could combine the two Event arrays (which contain the query results) into a single Event[]

For example:

Account[] a1 = [select id from account limit 2];
Account[] a2 = [select id from account limit 2];

Account[] a3 = new Account[]{};
for(Account tempAccount : a1)
a3.add(tempAccount);
for(Account tempAccount : a2)
a3.add(tempAccount);
jlojlo
Code:
t=[SELECT WhatId,Name__c,Description,ActivityDate,ActivityDateTime,Id,OwnerId,TimeConverted__c,RelatedName__c,Owner.Name 
   FROM Event  
   WHERE Type='In-Service'  
   AND (
          ((ActivityDate = THIS_MONTH or ActivityDate = NEXT_WEEK)) 
          OR 
          ((ActivityDate = LAST_N_DAYS:30) and Status__c='Completed')) 
 )
   AND (Owner.UserRole.ParentRoleId=:GroupId or ownerid=:Userid)
  ];