0

Query

Select id,name,phone,email,CampaignMember 
from lead 
where CampaignMember=:selectedcampaign

Error

No such column 'CampaignMember' on entity 'Lead'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names.

Please help me to modify this.

2
  • here "selectedcampaign" is campaign id
    – SFDC V
    Commented Apr 8, 2019 at 11:08
  • What is the condition that you are trying to form here and fetch the lead records?
    – Jayant Das
    Commented Apr 8, 2019 at 13:27

2 Answers 2

0

You can use select Id, Name, Phone, Email from Lead where Id in (select LeadId from CampaignMember where CampaignId = :selectedcampaign)

0

If you want to get lead details which is part of a campaign then you will have to query CampaignMember records first where LeadId is matching and then do another query on lead based on the found lead Ids.

Set<Id> lstLeadIds = new Set<Id>();
for(CampaignMember cm : [SELECT LeadId FROM CampaignMember WHERE CampaignId =:campaignId ) {
    lstLeadIds.add(cm.LeadId); 
}

//Query lead records 
List<Lead> lstLeads = [SELECT Id, Name, Phone, Email FROM Lead WHERE Id IN :lstLeadIds];

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .