You need to sign in to do that
Don't have an account?

Cannot Access to Campaign Field from Lead Object
Hi all,
My problem seems to be very simple...
I want to make for example this query: [select CampaignID from Lead]
The problem is that I don't have the name for Campaign field, I tried with Campaign and CampaignID but didn't work.
From my org, field name appears as Campaign. And if I look at Field-Level Security appears as Visible.
From Eclipse I can't see that field.
Any ideas?
Thanks,
Orlando
Sure - that shouldn't be too tricky with visualforce & apex. Assuming your VF field is called something like CampaignID__c, the query would look something like this:
All Answers
The Campaign field on Lead is a funky field that is not accessible via SOQL. It's primary purpose is for quick campaign member creation when a lead is created (typically via web to lead - pass the CampaignID to create the member).
What are you trying to do with that query? You'd be better off querying campaign member for the CampaignID for the desired leads.
If a lead trigger, might be something like this:
List<CampaignMember> cms=[SELECT CampaignID, LeadID, Status FROM CampaignMember WHERE LeadID in : Trigger.new()]; Set<ID> CampaignIDs= new Set<ID>(); For (CampaignMember cm:cms){ if(CampaignIDs.contains(cm.CampaignID)==FALSE){ CampaignIDs.add(cm.CampaignID); } } //Now you have a list of all the campaigns these leads are in.
Hi, thanks. I didn't know that.
I wrote that example to make it simply to understand.
Now, what I really need is this:
A user will enter a CampaignID from a lookup on my page.
Then, I'll need to list all Leads that has that CampaignID.
I can try thinking a solution now I have your example.
By the way, do you think is possible make what I'm trying to do?
Thanks
Sure - that shouldn't be too tricky with visualforce & apex. Assuming your VF field is called something like CampaignID__c, the query would look something like this:
Thanks, you're rigth!
It make sense,
Thanks again,
Orlando
btw-this will "break" for any campaigns with more than 1000 unique leadID's as a set can only hold 1000 items. You might want to add in a check for the size of the Set and "Break" the loop if the set has 999 items in it.
There are a bunch of other posts on how to bulkify code on these boards if you run into any other problems.
Yes, thanks.
I'm aware of that.
Thanks for your help!
Quick question on your code above. If I want to include the VF field on my lead page for the purpose of reporting on leads with/without campaigns, how would I go about adding the code?
Thank you!
Kyle