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
knght4yshuaknght4yshua 

System.QueryException: Non-selective query

Hey all,

I've read the other posts regarding this error and none of the solutions resolve my issue.  Here is the method in my Apex Class that is throwing the error:
 
@testVisible private static Map<Id, User> mAvailableMP {
	get {      
		if(mAvailableMP == null) {
			mAvailableMP = new Map<Id, User>();
			System.debug('SM_PROFILE_ID -----> '+SM_PROFILE_ID);
			List<User> lMP =
				[SELECT Id, Number_of_Assigned_Projects__c, Number_of_Peer_Audits_Assigned__c,Last_Project_Assigned_Date__c
				 FROM User 
				 WHERE Profile.Name = :MP_PROFILE
				 AND ProfileId != :SM_PROFILE_ID
				 AND UserRole.DeveloperName = :MP_REP_ROLE];               
			List<Availability__c> lOutOfOfficeAvailabilities =
				[SELECT OOO_Start_Date__c, OOO_End_Date__c 
				 FROM Availability__c
				 WHERE User__c IN :lMP 
				 AND OOO_Start_Date__c <= TODAY 
				 AND OOO_End_Date__c >= TODAY];          
			Set<Id> sOutOfOfficeUserIds = Pluck.ids('User__c', lOutOfOfficeAvailabilities);
			
			for(User u : lMP) {
				if(!sOutOfOfficeUserIds.contains(u.Id)) {
					mAvailableMP.put(u.Id, u);
				}
			}
		} 
		
		return mAvailableMP;
	}
	set;
}

For reference, here are the static variable assignments:
 
@testVisible private static final String MP_PROFILE = 'BCBSNC LG MP';

@testVisible private static final String MP_REP_ROLE = 'LG_MP_Reps';

@testVisible private static final Id SM_PROFILE_ID = [SELECT Id FROM Profile WHERE Name = 'SM User' LIMIT 1].Id;

When attempting the User query, to populate the lMP variable, I receive the System.QueryException error.  When debugging, the code definitely reaches the "System.debug('SM_PROFILE_ID -----> '+SM_PROFILE_ID);" line, but fails immediately after.  When running the same query in both Workbench and Dev Console I retrieve only a single record.  The User object DOES have over 200,000 records, BUT I am being selective in my query in three different ways, am I not?

​​​​​​​What is happening?