+ Start a Discussion
salesforce@14salesforce@14 

error in Query used in trigger

Hi,

Error: Invalid Data. 
Review all error messages below to correct your data.
Apex trigger Permissionset caused an unexpected exception, contact your administrator: Permissionset: execution of BeforeUpdate caused by: System.QueryException: Non-selective query against large object type (more than 100000 rows). Consider an indexed filter or contact salesforce.com about custom indexing. Even if a field is indexed a filter might still not be selective when: 1. The filter value includes null (for instance binding with a list that contains null) 2. Data skew exists whereby the number of matching rows is very large (for instance, filtering for a particular foreign key value that occurs many times): Trigger.Premissionset: line 6, column 1

trigger Permissionset on Permissionset__c (Before Update) 
{
   User usr = [SELECT Id,Profile.Name FROM User WHERE Id =:UserInfo.getUserId()];
   if(trigger.isUpdate && trigger.isBefore)
   {
       List<PermissionSetAssignment> lstcurrentUserPerSet = [SELECT AssigneeId FROM PermissionSetAssignment WHERE PermissionSet.Label LIKE '%Super%'];      
       for(Permissionset__c tt:Trigger.new)
       {       
           if(trigger.oldMap.get(tt.id).CTMax__Global_Usage__c == true  && lstcurrentUserPerSet[0].AssigneeId != usr.id && usr.Profile.Name != 'System Administrator')
           {
              tt.adderror('Only Super User has access to update the Master Template. Please Contact Super User');
           }
       }
   }
}

Thanks in Advance
RAM AnisettiRAM Anisetti
try to modifiy your code like below.
 
List<PermissionSetAssignment> lstcurrentUserPerSet = [SELECT AssigneeId FROM PermissionSetAssignment WHERE PermissionSet.Name LIKE '%Super%'];

 
salesforce@14salesforce@14
Hi Ram 

            Thanks for you response. but it couldnt work.

I think we have to use some Indexed fields in query. Do you know any Indexed fields in Permission sets?
 
RAM AnisettiRAM Anisetti
Hi Sai,

Use this below lines
 
List<PermissionSet> pid=[SELECT Id,Name FROM PermissionSet WHERE Name LIKE '%Super%'];
List<PermissionSetAssignment> lstcurrentUserPerSet = [SELECT AssigneeId FROM PermissionSetAssignment WHERE PermissionSetId IN :pid];
system.debug('----------'+lstcurrentUserPerSet);