+ Start a Discussion
LATHA RAJLATHA RAJ 

SOQL SUPPORT

PLEASE HELP WITH FOLLOWING QUERY...
 i am trying to fetch data from contact to two related custom objects 
SELECT id,name FROM Contact where ID IN (SELECT Contact__c FROM custom object 1 WHERE NAME ='abc') AND (SELECT Contact__c FROM custom object 2 WHERE Name ='xyz')
Sukesh Kumar 33Sukesh Kumar 33

You can do it in the following simple way:
 

Set<Id> setContactId = new Set<Id>();

for(object1 obj1 : [SELECT Contact__c FROM custom object 1 WHERE NAME ='abc']) {
	setContactId.add(obj1.Contact__c);
}

for(object1 obj2 : [SELECT Contact__c FROM custom object 2 WHERE NAME ='xyz']) {
	setContactId.add(obj2.Contact__c);
}

List<Contact> lstContact = [SELECT id,name FROM Contact where ID IN : setContactId];