Getting an error in Line 8 in the query in the constructor contactFindNextLastVisit
. Can someone see what that might be?
There are no SOQL statements in for loop.
public class ConNextEventUpdate_EventTriggerHelper {
public static void contactNextEventUpdate(List<Event> newEvents, List<Event> oldEvents, boolean isInsert, boolean isUpdate, boolean isDelete, boolean isUndelete)
{
//find contacts associated to the events that were created, deleted, or updated (both old and new values)
Set<ID> conIDs = new Set<ID>();
//get contact ids for newly inserted/updated record
if (isInsert || isUpdate || isUndelete) {
for (Event e : newEvents) {
if (e.WhoId != null && e.Group_Event_Lookup__c == Null) {
//a WhoId starting with '003' is a contact
if ( String.valueOf(e.WhoId).startsWith('003') ) {
system.debug('Inside First If-----------------------contactLastNextVisitUpdate');
conIDs.add(e.WhoId);
}
}
}
}
//get contact ids for deleted record or previous value of updated record
if (isDelete || isUpdate) {
for (Event e : oldEvents) {
if (e.WhoId != null && e.Group_Event_Lookup__c == Null) {
//a WhoId starting with '003' is a contact
if ( String.valueOf(e.WhoId).startsWith('003') ) {
system.debug('Inside Second If-----------------------contactLastNextVisitUpdate');
conIDs.add(e.WhoId);
}
}
}
}
//now that we have our contact ids, we need to get the contact records and all events associated to those contacts
/*
Publish date for next or last “qualifying event”
- Next Visit
- Last visit
Definition of “qualifying Event”:
“Cancelled” not equal to True
“DM not met” not equal to True
Events that are related to one account but have less than four attendees (contacts) associated to the same event.
Type = Visit activities
*/
List<Contact> cons2Update = new contactFindNextLastVisit(conIDs).cons2Update;
system.debug('List cons2Update: '+cons2Update);
system.debug('cons2Update.size(): '+cons2Update.size());
//update the contacts
if (cons2Update.size() > 0) {
update cons2Update;
}
}
}
public class contactFindNextLastVisit {
public List<Contact> cons2Update {get;set;}
//constructor
public contactFindNextLastVisit(Set<ID> conIDs) {
system.debug('conIDs.size():' +conIDs.size());
List<Event> lstEvents = [Select Id
, WhoId
, Event_Type__c
, ActivityDate
, (Select Id, EventId, AttendeeId From EventAttendees)
From Event
Where WhoId in :conIDs
AND Event_Type__c = 'Visit activities'
AND Cance_lled__c = false
AND DM_not_met__c = false
AND Group_Event_Lookup__c = Null
Order By WhoId, ActivityDate];
//loop through each contact and find the activities for it
Boolean bEventContactFound;
Boolean bEventContactUpdated;
Date dtLastVisit;
Date dtNextVisit;
Date dtLastVisitDefault = date.newInstance(1980, 1, 1);
Date dtNextVisitDefault = date.newInstance(2200, 1, 1);
this.cons2Update = new List<Contact>();
system.debug('conIDs.size(): '+conIDs.size());
List<Contact> conList = [Select Id, Next_Visit__c, Last_Visit__c From Contact
Where Id in :conIDs
Order By Id];
for (Contact c : conList) {
//reset variables as we start a new contact
bEventContactFound = false;
bEventContactUpdated = false;
dtLastVisit = dtLastVisitDefault;
dtNextVisit = dtNextVisitDefault;
//loop through all events and find those linked to the current contact
for (Event e : lstEvents) {
if (e.WhoId == c.Id) {
bEventContactFound = true;
if (e.EventAttendees.size() < 4) {
if ( (e.ActivityDate > dtLastVisit) && (e.ActivityDate <= date.today()) ) {
dtLastVisit = e.ActivityDate;
}
if ( (e.ActivityDate < dtNextVisit) && (e.ActivityDate > date.today()) ) {
dtNextVisit = e.ActivityDate;
}
}
} else if (bEventContactFound) {
//we've already processed the contact so we can quit the loop
break;
}
}
//set the last visit value on the contact
if (c.Last_Visit__c <> dtLastVisit) {
bEventContactUpdated = true;
if (dtLastVisit == dtLastVisitDefault) {
c.Last_Visit__c = null;
} else {
c.Last_Visit__c = dtLastVisit;
}
}
//set the next visit value on the contact
if (c.Next_Visit__c <> dtNextVisit) {
bEventContactUpdated = true;
if (dtNextVisit == dtNextVisitDefault) {
c.Next_Visit__c = null;
} else {
c.Next_Visit__c = dtNextVisit;
}
}
//add the contact to our update list
if (bEventContactUpdated) {
this.cons2Update.add(c);
}
}
}
}
update cons2Update
may set off recursion - that's where I'd start looking first