You need to sign in to do that
Don't have an account?
blake.tanon
Class: Attempt to de-reference a null object
I'm trying to get a list of contact ids out of a list of campaignmembers, to do this i first build the list of campaign members, then attempt to put the contactid into a set. I'm running into the error at this point and can't figure out out to fix it.
global with sharing class CampaignROI_Reps{ public static list<CampaignMember> cList; public static set<id> contacts; public AggregateResult SalesResultsPost30 {get;set;} public CampaignROI_Reps(){ //get distribution aggregate data cList = [SELECT id, contactid, campaignid, rep_name__c, firm__c, reit_sales__c, reit_tickets__c, calls__c, meetings__c, pipeline__c, territory__c FROM CampaignMember WHERE Campaignid =:ApexPages.currentPage().getParameters().get('id')]; if(clist.size() > 0){ for(campaignmember c:clist){ if(c.contactid != null){ contacts.add(c.contactid); } } } SalesResultsPost30 = [SELECT SUM(Gross_Amount__c) total1 FROM Transaction__c WHERE Rep__c in: contacts AND trade_date__c >: date.valueof(ApexPages.currentPage().getParameters().get('enddate')) AND trade_date__c <: date.valueof(ApexPages.currentPage().getParameters().get('enddate')) + 30]; } public static list<CampaignMember> getcList(){ return clist; } }
Hi
You need to initialize the list
public CampaignROI_Reps(){
cList = new List<CampaignMember>();
//get distribution aggregate data
cList = [SELECT id, contactid, campaignid, rep_name__c, firm__c,
reit_sales__c, reit_tickets__c, calls__c, meetings__c, pipeline__c,
territory__c
FROM CampaignMember
WHERE Campaignid =:ApexPages.currentPage().getParameters().get('id')];
if(clist.size() > 0){
for(campaignmember c:clist){
if(c.contactid != null){
contacts.add(c.contactid);
}
}
}
SalesResultsPost30 = [SELECT SUM(Gross_Amount__c) total1
FROM Transaction__c
WHERE Rep__c in: contacts AND
trade_date__c >: date.valueof(ApexPages.currentPage().getParameters().get('enddate')) AND
trade_date__c <: date.valueof(ApexPages.currentPage().getParameters().get('enddate')) + 30];
}
Hi,
Can you try with the following code,
global with sharing class CampaignROI_Reps{
public static list<CampaignMember> cList;
public static set<id> contacts;
public AggregateResult SalesResultsPost30 {get;set;}
public CampaignROI_Reps(){
//get distribution aggregate data
cList = [SELECT id, contactid, campaignid, rep_name__c, firm__c,
reit_sales__c, reit_tickets__c, calls__c, meetings__c, pipeline__c,
territory__c
FROM CampaignMember
WHERE Campaignid =:ApexPages.currentPage().getParameters().get('id')];
System.debug('Size is '+cList.size());
if(clist.size() > 0){
for(campaignmember c:clist){
if(c.contactid != null){
contacts.add(c.contactid);
}
}
}
if (!contacts.isEmpty()){
SalesResultsPost30 = [SELECT SUM(Gross_Amount__c) total1
FROM Transaction__c
WHERE Rep__c in: contacts AND
trade_date__c >: date.valueof(ApexPages.currentPage().getParameters().get('enddate')) AND
trade_date__c <: date.valueof(ApexPages.currentPage().getParameters().get('enddate')) + 30];
}
}
public static list<CampaignMember> getcList(){
return clist;
}
}
yes. markoLomat is right.