function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
stcforcestcforce 

filter by null returning nulls, please help if possible, thankyou

ran the following and it keeps giving me back results in which the event's whoid field is null. Can anyone tell me what i am doing wrong? I've tried a couple different ways to reorder the query but it just keeps giving me back results with null. Can anyone tell me under what circumstance i can't trust testing such against null (it seems important) ? thank you.

 

contact[] cs= [Select c.id fromContact c

where c.isDeleted=false and c.hasoptedoutofemail=true];

lead[] lds= [Select l.id fromLead l

where l.isDeleted=false and l.HasOptedOutOfEmail=true];

 

datetime now=system.now();

datetime threeDaysAhead= now.addDays(3); datetime fourDaysAhead= now.addDays(4);

Event[] evs= [Select e.id, e.confirmEmail__c FromEvent e

where e.startdatetime>=:threeDaysAhead and e.startdatetime<:fourDaysAhead

and e.isDeleted=false and e.whoid not in :lds and e.whoid not in :cs

and e.whoid!=null

Order by e.startdatetime ASC Limit 400];

Navatar_DbSupNavatar_DbSup

Hi,


I think you want to find the entire event whose whoId is null or blank?????? If yes then you have to modify the query. There is no need to check the whoid not in contact or lead list. Your whoid condition is contradict with other. In one case you are saying whoid not belong to contact or lead id while on other hand you are saying whoid !=null. Hence this is the contradiction if there is no whoid then value should be null , so you have to make the condition on null.Here you can simply write whoid = null simple. Your query should be like this:


datetime now=system.now();
datetime threeDaysAhead= now.addDays(3); datetime fourDaysAhead= now.addDays(4);
Event[] evs= [Select e.id From Event e
where e.startdatetime>=:threeDaysAhead and e.startdatetime<:fourDaysAhead
and e.isDeleted=false and e.whoid=null
Order by e.startdatetime ASC Limit 400];
system.debug('@@@@@@@@@@@@@@@@@' +evs);

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

stcforcestcforce

actually i want to find those events for which there is a non-null value for whoid and where the related contact/lead hasn't opted out of being emailed. I am attempting to write code for emailing contacts regarding their meetings.