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
RajashriRajashri 

Initial term of field expression must be a concrete SObject: LIST<Lead>

Hi,

I am trying to assign the lead id but i am getting the error as  Initial term of field expression must be a concrete SObject: LIST<Lead> 

Can anyone Please help?
public with sharing class CampaignMemController {
    public Campaign camp {get; set; }
    public CampaignMemController(ApexPages.StandardController controller) {
     camp = (Campaign)controller.getRecord();
    }
   public List<Lead> lead;
   public List<Lead> leadlist = new list<Lead>();
    public List<Lead> cmlist;
    public List<Lead> getLead() {
        if(lead == null) {
           lead = [SELECT Id,Name FROM Lead];
          
        }
            return lead;
         }
    public List<Lead> CampaignMembers;
    public List<Lead> getCampaignMembers() {
     CampaignMembers=[Select Id,Name,(SELECT id, contactid FROM campaignmembers WHERE Id = :camp.Id AND LeadId != null ) from Lead WHERE Id= :lead.id ];
        return CampaignMembers;
       }
       
    
    }
Virendra ChouhanVirendra Chouhan
Hi,

Here the problem is your Lead is a List type variable so you can't access a list like lead.id
You have to mention the index.
in your case i think you have to use loop for that list. (If you have many leads )
Other wise set 0 index on it
i.e lead[0].id

Regards
Virendra
RajashriRajashri
Thanks Virendra..Yes there are many leads and i want to pick the current list value..

Can you please tell me how to use loop to get the current  lead value?

Thanks
Virendra ChouhanVirendra Chouhan
Hi
What do you mean by current Lead?
RajashriRajashri
Current Lead means Lead associated with the Campaign Member....

"In campaign Layout" there is one section "Campaign Member" in that we get the campaign member details...so basically i am trying to customize those details through code."
Virendra ChouhanVirendra Chouhan
And i think you don't need of  lead if you want to return CampaignMembers.
I mean if you have a campaign id then you can find the CampaignMembers realated it.
SELECT id,name FROM CampaignMember WHERE campaignid =:camp.id
 
RajashriRajashri
i am displaying the Activity History from the Lead..that's the reason i need to go to the Lead Id
Virendra ChouhanVirendra Chouhan
Hi Rajashri,
You have to use Set instead of list.

1.so you can write set on the query
first change your list of lead to set.
set<Lead> sLead = new set<Lead>([SELECT id FROM Lead]);
ANd then
CampaignMembers=[Select Id,Name,(SELECT id, contactid FROM campaignmembers WHERE Id = :camp.Id AND LeadId != null ) from Lead WHERE Id IN : slead ];

2. Or you have to use For loop. like
first create a Set (type of Id)
set<id> lead_Id = new set<id>();
for(Lead le : lead){

lead_id.add(le.id);
}
After that SOQL query:
 
CampaignMembers=[Select Id,Name,(SELECT id, contactid FROM campaignmembers WHERE Id = :camp.Id AND LeadId != null ) from Lead WHERE Id IN : lead_Id ];

try any one of them.
Note:The code is not tested so correct syntaxt eror if occure.


Regards
Virendra

 
RajashriRajashri
Thanks..I tried but it's still displaying me all the campaign member..I want to display only the campaign member records associated with that campaign
Virendra ChouhanVirendra Chouhan
Oh ok !
try this Query
[SELECT id  FROM campaignmembers WHERE CampaignId  = :camp.Id AND LeadId IN : slead]
(If you created a SET slead)

Other wise 
[SELECT id  FROM campaignmembers WHERE CampaignId  = :camp.Id AND LeadId IN : lead_Id]
(When you used loop and SET of id Lead_Id)

 
RajashriRajashri
Thanks Vrendra but It's still listing all the campaign..

Below is my code..

public with sharing class CampaignMemController {
    public Campaign camp {get; set; }
    public CampaignMemController(ApexPages.StandardController controller) {
     camp = (Campaign)controller.getRecord();
    }
   
    List<Lead> sLead = new List<Lead>([SELECT id FROM Lead]);
    List<Lead> leadlist = new list<Lead>();
    public List<Lead> CampaignMembers;
    public List<Lead> getCampaignMembers() {
       CampaignMembers=[Select Id,Name,(Select id, Campaign.Name,Contact.Phone,Lead.FirstName,Lead.LastName,LeadID,ContactID,Lead.Phone,Lead.Email, Lastmodifieddate,Status,CampaignId,Campign_ID__c,Lead.MobilePhone  From CampaignMembers where CampaignId =:camp.Id and Status != '' and LeadId IN : slead ), 
(Select Subject, Id,lastModifiedDate From ActivityHistories  where lastModifiedDate !=null and Subject !=null order by LastModifiedDate desc limit 1) 
 from Lead WHERE Id IN : slead and Name !=NULL  order by LastModifiedDate desc];
       return CampaignMembers;
       }
    
        
     }
Virendra ChouhanVirendra Chouhan
Hi
you can't use list like where id IN :
so raplace this code:
List<Lead> sLead = new List<Lead>([SELECT id FROM Lead]);
with this
Set<Id> sLead = new set<Id>([SELECT id FROM Lead]);



 
RajashriRajashri
Hi,
I tried that also...Now i am getting an error on highlighted line

Error:  Invalid initial value type LIST<Lead> for SET<Id> 


public with sharing class CampaignMemController {
    public Campaign camp {get; set; }
    public CampaignMemController(ApexPages.StandardController controller) {
     camp = (Campaign)controller.getRecord();
    }
  
  Set<Id> sLead = new set<Id>([SELECT id FROM Lead]);
    List<Lead> leadlist = new list<Lead>();
    public List<Lead> CampaignMembers;
    public List<Lead> getCampaignMembers() {
       CampaignMembers=[Select Id,Name,(Select id, Campaign.Name,Contact.Phone,Lead.FirstName,Lead.LastName,LeadID,ContactID,Lead.Phone,Lead.Email, Lastmodifieddate,Status,CampaignId,Campign_ID__c,Lead.MobilePhone  From CampaignMembers where CampaignId =:camp.Id and Status != '' and LeadId IN : slead ), 
(Select Subject, Id,lastModifiedDate From ActivityHistories  where lastModifiedDate !=null and Subject !=null order by LastModifiedDate desc limit 1) 
 from Lead WHERE Id IN : slead and Name !=NULL  order by LastModifiedDate desc];
       return CampaignMembers;
       }
    
        
     }