I have tried this. Not working. (CampaignIds is a set)

for (Lead lead : Trigger.new) {
  • 1
    can you post your whole code, and explain what you are trying to achieve? Commented Apr 18, 2016 at 10:33
  • The other codes are not relevant. I am trying to save the lead's campaign IDs in a set. But for some reasons lead.CampaignId cannot get that. @MarcZaharescu
    – Oladipo
    Commented Apr 18, 2016 at 10:41
  • How you can say that other codes are not relevant if this is the case then only you can solve this problem we can't help you; Commented Apr 18, 2016 at 10:44
  • Somebody has helped without the other codes. @itzmukeshy7
    – Oladipo
    Commented Apr 18, 2016 at 10:55
  • @DIPXOID That is great!!! Commented Apr 18, 2016 at 10:57

2 Answers 2


[SELECT Id, CampaignId, LeadId FROM CampaignMember WHERE LeadId IN :leadsInTrigger ]

Using this query you get all campaign member for the leads that are in your trigger scope. From that you should be able to determine for which campaigns each lead is a member.


As per the documentation, the Campaign field on the Lead object is not accessible via the API. So you will have to do this via the Campaign Member object, which associates leads and campaigns together.

Code from here may be helpful.

You must log in to answer this question.

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