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
mahimahi 

Relationship query on campaign

Hi All,
 
when i write
 
for(campaign camp : [SELECT Name, (SELECT id FROM tasks) FROM Campaign where name='1-ID-H-NAS-37']){
task [ ] l= camp.tasks;
 
}
 
no error is given but when i write
 
for(campaign camp : [SELECT Name, (SELECT id FROM leads) FROM Campaign where name='1-ID-H-NAS-37']){
lead[ ] l= camp.leads;
 
}
 
an error is thrown saying, "Invalid field leads for SObject Campaign"..
 
I checked in WSDL, both Leads and Tasks are present under Campaign object .
 
Could anybody please comment on it. why it is happening?
 
Thanks,
Mahi
NasipuriNasipuri

Hi Mahi,

 

The relationship between the Campaign and Lead is not like the relationship between campaign and task.

 

The Task is a child of campaign but not the lead.

 

I think you are probably tiring to get all the leads which are associated to a particular campaign member.

 

For this just find out the Campaign id.

And fire the below query

 

Select LeadId FROM CAMPAIGNMEMBER WHERE campaignid= ''

 

Thanks and Regards,

Dinesh Nasipuri