0 votes
5 views
by

I have a custom object Customer__c that stores contact and address information (along with other information).

Every time a contact is created without inserting an address, a record of Customer__c is created with Contact_ID__c = 'contacts id' and type = 'Contact'.

Every time a contact is created with address, two records of Customer__c are created. One with type = 'Contact' and another with type = 'Address'. Both have Contact_ID__c = 'contacts id'

If I am given a set of Contact_ID__c, how can I query for records of Customer__c that only have a record of type = 'Contact' and don't have a record of type = 'Address'? In other words, I want to get the contacts in the set that don't have an address.

Is it possible? Thank You.

1 Answer

0 votes
by
 
Best answer

I agree with Phil's approach, but I feel it could probably be achieved with an SOQL subquery something like this :

SELECT Id, Name 
FROM Contact__c 
WHERE Id NOT IN (
  SELECT Contact_Id__c 
  FROM Customer__c 
  WHERE Type__c = 'Address'
)
Welcome to Memory Exceeded, where you can ask questions and receive answers from other members of the community.
...