You need to sign in to do that
Don't have an account?
Stephanie Zimmerman 7
Referencing Event.Type picklist values in Apex Batch Class
Hello all,
Hoping this will be a quick and easy question. I currently have a batch class to send emails on Event. The batch class is referenced by a schedulable class; the schedulable class runs daily. For the portion of the code that queries the Event records, I am looking to make a small modification to exclude Events where Type = Rescheduled or Cancelled.
Previously, this was the code and emails were sending:
for(Event evnt : eventLst){
if(evnt.WhatId != null && String.valueOf(evnt.WhatId).startsWith(PREFIX_OPPORTUNITY) && evnt.WhoId != null && String.valueOf(evnt.WhoId).startsWith(PREFIX_CONTACT)){
//Opportunity Id set
oppIdSet.add(evnt.WhatId);
//Contact Id set
contIdSet.add(evnt.WhoId);
}
}
Now this is the updated code attempting to exclude Events where Type = Rescheduled or Cancelled
for(Event evnt : eventLst){
if(evnt.Type != 'Rescheduled' && evnt.Type != 'Cancelled' && evnt.WhatId != null && String.valueOf(evnt.WhatId).startsWith(PREFIX_OPPORTUNITY) && evnt.WhoId != null && String.valueOf(evnt.WhoId).startsWith(PREFIX_CONTACT)){
//Opportunity Id set
oppIdSet.add(evnt.WhatId);
//Contact Id set
contIdSet.add(evnt.WhoId);
}
}
With this change, now no emails are sending, even when Type is null. I assume I'm referencing picklist values incorrectly but am not sure how to correct. Any ideas for the best way to write this code to exclude Events where Type = Rescheduled or Cancelled?
Thanks!
Stephanie
Hoping this will be a quick and easy question. I currently have a batch class to send emails on Event. The batch class is referenced by a schedulable class; the schedulable class runs daily. For the portion of the code that queries the Event records, I am looking to make a small modification to exclude Events where Type = Rescheduled or Cancelled.
Previously, this was the code and emails were sending:
for(Event evnt : eventLst){
if(evnt.WhatId != null && String.valueOf(evnt.WhatId).startsWith(PREFIX_OPPORTUNITY) && evnt.WhoId != null && String.valueOf(evnt.WhoId).startsWith(PREFIX_CONTACT)){
//Opportunity Id set
oppIdSet.add(evnt.WhatId);
//Contact Id set
contIdSet.add(evnt.WhoId);
}
}
Now this is the updated code attempting to exclude Events where Type = Rescheduled or Cancelled
for(Event evnt : eventLst){
if(evnt.Type != 'Rescheduled' && evnt.Type != 'Cancelled' && evnt.WhatId != null && String.valueOf(evnt.WhatId).startsWith(PREFIX_OPPORTUNITY) && evnt.WhoId != null && String.valueOf(evnt.WhoId).startsWith(PREFIX_CONTACT)){
//Opportunity Id set
oppIdSet.add(evnt.WhatId);
//Contact Id set
contIdSet.add(evnt.WhoId);
}
}
With this change, now no emails are sending, even when Type is null. I assume I'm referencing picklist values incorrectly but am not sure how to correct. Any ideas for the best way to write this code to exclude Events where Type = Rescheduled or Cancelled?
Thanks!
Stephanie