I started receiving lot of these errors, I'm not sure how to handle this the query that's causing this error is,
public static void updatePartnerLeadCount(set<Id> setPartnerIds){
//Map will contain one Lead Id to one sum value
List<Partner__c> lstpartnercount=new List<Partner__c>();
map<Id,integer> LeadCountMap = new map<Id,integer>();
map<Id,datetime> LeadDateMap = new map<Id,datetime>();
for(AggregateResult q : [select Partner__c,Count(Id),max(CreatedDate)
from Lead where Partner__c IN :setPartnerIds group by Partner__c]){
LeadCountMap.put((Id)q.get('Partner__c'),(integer)q.get('expr0'));
LeadDateMap.put((Id)q.get('Partner__c'),(Datetime)q.get('expr1'));
}
for(Partner__c p:[Select Id,of_Leads_Sent__c,Date_of_last_lead__c from Partner__c where ID IN:LeadCountMap.keyset()]){
p.of_Leads_Sent__c=LeadCountMap.get(p.Id);
p.Date_of_last_lead__c=LeadDateMap.get(p.Id).date();
lstpartnercount.add(p);
}
update lstpartnercount;
}
my error message is pointing to -
for(AggregateResult q : [select Partner__c,Count(Id),max(CreatedDate) from Lead where Partner__c IN :setPartnerIds group by Partner__c]){ LeadCountMap.put((Id)q.get('Partner__c'),(integer)q.get('expr0')); LeadDateMap.put((Id)q.get('Partner__c'),(Datetime)q.get('expr1')); }
What am I trying to do in the code ? - I have a Partner Object(custom) and its related list Lead, this is to get the number of leads(of_Leads_Sent__c
) and also to find out the date of the last lead (Date_of_last_lead__c
)
setPartnerIds
does not containnull
by callingsetPartnerIds.remove(null)
before running your query.