You need to sign in to do that
Don't have an account?
Rajashri
Error: Invalid foreign key relationship: Lead.ActivityHistories
Hi,
I am trying to add the "Subject" Field for Lead from "Lead Activity History" table but i am getting an error that
"Invalid foreign key relationship: Lead.ActivityHistories" Can anyone please tell me how to add the Subject field in list.
Below is my code
public with sharing class singleListView {
public Campaign camp {get; set; }
public List<MemberWrapper> lMemberWrappers {get; set;}
public singleListView(ApexPages.StandardController controller) {
camp = (Campaign)controller.getRecord();
lMemberWrappers = new List<MemberWrapper>();
getCampaignMembers();
getContactMembers();
for(Lead ld : CampaignMembers) {
lMemberWrappers.add(new MemberWrapper(ld.Phone,ld.ActivityHistories.Subject));
}
}
private List<Lead> CampaignMembers;
public List<Lead> getCampaignMembers() {
CampaignMembers = [Select Id,Name, Phone,(Select id, Campaign.Name,Contact.Phone,Lead.FirstName,Lead.LastName,Lead.Name,LeadID,ContactID,Lead.Phone,Lead.Email, Lastmodifieddate,Status,CampaignId,Campign_ID__c,Lead.MobilePhone From CampaignMembers where CampaignId =:camp.Id and Status != '' ),
(Select Subject, Id,lastModifiedDate From ActivityHistories where lastModifiedDate !=null and Subject !=null order by LastModifiedDate desc limit 1)
From Lead where Id IN(select LeadId from campaignMember where campaignId =:camp.Id ) order by LastModifiedDate desc];
return CampaignMembers;
}
public class MemberWrapper {
public String Phone {get; set;}
public String Subject{get;set;}
public MemberWrapper(String Phone,String Subject ) {
this.Phone = Phone;
this.Subject=Subject;
}
}
}
I am trying to add the "Subject" Field for Lead from "Lead Activity History" table but i am getting an error that
"Invalid foreign key relationship: Lead.ActivityHistories" Can anyone please tell me how to add the Subject field in list.
Below is my code
public with sharing class singleListView {
public Campaign camp {get; set; }
public List<MemberWrapper> lMemberWrappers {get; set;}
public singleListView(ApexPages.StandardController controller) {
camp = (Campaign)controller.getRecord();
lMemberWrappers = new List<MemberWrapper>();
getCampaignMembers();
getContactMembers();
for(Lead ld : CampaignMembers) {
lMemberWrappers.add(new MemberWrapper(ld.Phone,ld.ActivityHistories.Subject));
}
}
private List<Lead> CampaignMembers;
public List<Lead> getCampaignMembers() {
CampaignMembers = [Select Id,Name, Phone,(Select id, Campaign.Name,Contact.Phone,Lead.FirstName,Lead.LastName,Lead.Name,LeadID,ContactID,Lead.Phone,Lead.Email, Lastmodifieddate,Status,CampaignId,Campign_ID__c,Lead.MobilePhone From CampaignMembers where CampaignId =:camp.Id and Status != '' ),
(Select Subject, Id,lastModifiedDate From ActivityHistories where lastModifiedDate !=null and Subject !=null order by LastModifiedDate desc limit 1)
From Lead where Id IN(select LeadId from campaignMember where campaignId =:camp.Id ) order by LastModifiedDate desc];
return CampaignMembers;
}
public class MemberWrapper {
public String Phone {get; set;}
public String Subject{get;set;}
public MemberWrapper(String Phone,String Subject ) {
this.Phone = Phone;
this.Subject=Subject;
}
}
}
Approach 1: Approach 2:
Based on your scenario you can access activity history from the above two approaches.
All Answers
Approach 1: Approach 2:
Based on your scenario you can access activity history from the above two approaches.
I want to display the records eventhough Subject Field is null.How can i do that?
In you SOQL Query you have checked the not null conditon, so remove the condition in your query, the modified query is