+ Start a Discussion
foodrunnerfoodrunner 

Query for a list of lead/Contact owners associated with active Campaigns

I am working with an unmanaged package from the appexchange and force.com labs called Campaign Call Down, and have been troubleshooting this requirement for customization for several hours.

 

I am needing to query across all active campaigns to formulate a list of campaign members by owner dropdown list. I have tried to create a nested soql statement but am coming up with an error

Error: Compile Error: Initial term of field expression must be a concrete SObject: LIST<Lead> at line 416 column 44

 

Here is my Code:

    public List<SelectOption> getowneritems(){
        List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption( '1', 'SELECT' ));
        for( Campaign c:getactiveCampaigns()){
            options.add( new SelectOption( lead.ownerid, c.leadowner.name));
        }
        return options;


    public List<Campaign> getactiveCampaigns(){
        if( activeCampaigns == null ){
            activeCampaigns = [select id, (select lead.Ownerid, Contact.ownerid from CampaignMembers),
            Name, Ownerid, Owner.id, owner.name
            From Campaign where isActive = true and
            Include_in_Campaign_Call_Down__c = true order by name LIMIT 100];
        }
        return activeCampaigns;
    }

 

 

How can I fix this?

Thank you

dmchengdmcheng

The options.add line doesn't look right - shouldn't it be:

 

options.add( new SelectOption( c.lead.ownerid, c.lead.owner.name));
hisrinuhisrinu

I think this should be

 

options.add( new SelectOption( c.CampaignMembers.ownerid, c.CampaignMembers.owner.name));
foodrunnerfoodrunner

I have made the changes and recieve the following error:

Compile Error: Invalid foreign key relationship: Campaign.CampaignMembers 

 

Here is the amended code:

    public List<SelectOption> getowneritems(){
        List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption( '1', 'SELECT' ));
        for( Campaign c:getactiveCampaigns()){
            options.add( new SelectOption( c.CampaignMembers.ownerid, c.CampaignMembers.owner.name));
        }
        return options;

 

 

How do I solve this?

 

Thank you

dmchengdmcheng

CampaignMember has lookup fields to Lead and Contact, so you can refer to the Lead or Contact owner by Campaign.CampaignMember.Lead.ownerId etc.  You'll need to do SOQL relationship queries to pull those values before you construct the SelectObjects list.