I am quite stuck regarding a query. I have three objects in Salesforce: Contact, CampaignMember, Campaign. Now, I want to get all the contacts which are in campaign 'A' but NOT in campaign 'B'. My code belwo doesn't work:
SELECT Contact.FirstName, Contact.LastName, Contact.ID FROM CampaignMember WHERE Campaign.Name= 'A' AND Campaign.Name != 'B'
Salesforce simply ignores the part:
AND Campaign.Name != 'B'
Nevertheless I get all the contacts which are in 'A'. Not the difference between A&B, which I wanted.
If I switch to != B
only, it returns zero contacts, which is not correct.
I suppose it is because the link between campaign and contact is made through the campaignmember object and I am trying to do a left outer join on the campaign where I want the contacts of campaign 'A' which are not in 'B'.
Is there a way to get this done? I would appreciate any help.
Thank you very much!