You need to sign in to do that
Don't have an account?
Yogesh Biyani
How do I merge the result of two different queries for the same contacts
SOQL statements cannot query more than 20 different child types.
So how do I merge the Contacts from two different queries?
For eg.
So how do I merge the Contacts from two different queries?
For eg.
List<Contact> querychilds1 = [select id,Orphan__c , (Select id from PrimaryContact__r ), (Select id from Attachments ), (Select id from CampaignMembers ), (Select id from Cases ), (Select id from CaseContactRoles ) and few more totaling to twenty.... from contact WHERE id IN :listofcontacts]; List<Contact> querychilds2 = [select id,Orphan__c , (Select id from Feeds ), (Select id from Histories ), (Select id from DeclinedEventRelations ), (Select id from DuplicateRecordItems ), (Select id from EmailMessageRelations ), (Select id from FeedSubscriptionsForEntity ) from contact WHERE id IN :listofcontacts];
If its list you can able to do it as below
Map<id,Contact> mapidcon1= new Map<id,Account>([select id,Orphan__c ,
(Select id from PrimaryContact__r ),
(Select id from Attachments ),
(Select id from CampaignMembers ),
(Select id from Cases ),
(Select id from CaseContactRoles )
and few more totaling to twenty....
from contact
WHERE id IN :listofcontacts]);
Map<id,Contact> mapidcon2= new Map<id,Account>([select id,Orphan__c ,
(Select id from Feeds ),
(Select id from Histories ),
(Select id from DeclinedEventRelations ),
(Select id from DuplicateRecordItems ),
(Select id from EmailMessageRelations ),
(Select id from FeedSubscriptionsForEntity )
from contact
WHERE id IN :listofcontacts]);
execute you logic as following:-
for(Contact c:[select id,Orphan__c from Conatct WHERE id IN :listofcontacts]){
//execute your query
system.debug(mapidcon1.get(c.id).PrimaryContact__r ); // this will hold all the primary contact related to particular contact
system.debug(mapidcon1.get(c.id).Feeds ); // this will hold all the feeds related to particular contact
}