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
mukesh guptamukesh gupta 

child-parent

Hi Expert,

I want to search Campaign for particular lead. can you plesae suggest with soql.

Thanks
Mukesh
Best Answer chosen by mukesh gupta
Amit Singh 1Amit Singh 1
Below is SOQL for your requirement.
 
List<Campaign> cmap = [Select Id From Campaign Where Id In(Select CampaignId From CampaignMember Where LeadID='Your Lead Id here')];

let me know if this helps :)

Thanks,
Amit Singh

All Answers

NagendraNagendra (Salesforce Developers) 
Hi Mukesh,

May I suggest you please give a try using the code below.
List<CampaignMember> cms=[SELECT CampaignID, LeadID, Status FROM CampaignMember WHERE CampaignID =: CampaignID__c];<br><br>Set<ID> LeadIDs= new Set<ID>();<br><br>For (CampaignMember  cm:cms){<br>  if(LeadIDs.contains(cm.LeadID)==FALSE){<br>    LeadIDs.add(cm.LeadID);<br>  }<br>}<br>//Now you have a list of all the campaigns these leads are in.
Hope this helps.

Mark this as solved if the information helps so that it gets removed from the unanswered queue which results in helping others who are encountering a similar issue.

Best Regards,
Nagendra.
 
Amit Singh 1Amit Singh 1
Below is SOQL for your requirement.
 
List<Campaign> cmap = [Select Id From Campaign Where Id In(Select CampaignId From CampaignMember Where LeadID='Your Lead Id here')];

let me know if this helps :)

Thanks,
Amit Singh
This was selected as the best answer