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
Alexandra StehmanAlexandra Stehman 

Querying for Campaign Member data for campaigns in a date range

I am trying to find campaign members for campaigns executed in last 2 years (not via Apex), in order to migrate this data (using Jitterbit).

I have tried couple different queries (from developer console) and can't seem to get the right query. Campaign is a lookup on CampaignMember, so should I not be able to use the __r notation to access?
 
SELECT Id, CampaignId, ContactId, CreatedById, CreatedDate, FirstRespondedDate, HasResponded, IsDeleted, LastModifiedById, LastModifiedDate, LeadId, Status, SystemModstamp 
FROM CampaignMember
where CampaignId = Campaign__r.id and Campaign__r.CreatedDate >= LAST_N_YEARS:2


 
Ashish_Sharma_DEVSFDCAshish_Sharma_DEVSFDC
Hi Alex,

Please try below query,As it is standard relationship so no need to use '--r' .
SELECT Id, CampaignId, ContactId, CreatedById, CreatedDate, FirstRespondedDate, HasResponded, IsDeleted, LastModifiedById, LastModifiedDate, LeadId, Status, SystemModstamp 
FROM CampaignMember
where CampaignId = Campaign.id and Campaign.CreatedDate >= LAST_N_YEARS:2

Let us know if it helps.
Alexandra StehmanAlexandra Stehman
Ashish,

Thank you. I did try that initially. I get 'bind variables' error:

User-added image
Alexandra StehmanAlexandra Stehman

SELECT Id, CampaignId, ContactId, CreatedById, CreatedDate, FirstRespondedDate, HasResponded, IsDeleted, LastModifiedById, LastModifiedDate, LeadId, Status, SystemModstamp FROM CampaignMember 
where
CampaignId in
(SELECT Id FROM Campaign WHERE CreatedDate >= LAST_N_YEARS:2)
I think this will do the trick.