You need to sign in to do that
Don't have an account?
Allen2
please help me to correct the below trigger
Want to write a trigger on user, so for any user has einstein user package license, if any user of profile other than system admin and standard security is trying to update the user's profile should throw an error.
Also if the profile is changed to the new profile with prefix SM then also should throw the error.
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger UserTrigger caused an unexpected exception, contact your administrator: UserTrigger: execution of BeforeUpdate caused by: System.QueryException: Non-selective query against large object type (more than 200000 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): ()
Also if the profile is changed to the new profile with prefix SM then also should throw the error.
public class errorMsgOnProfileUpdate { public static void errorMsgOnProfileChange (List<user> userList, Map<id,user> oldMap) { profile pf; userList = [Select Id, Profile.Name, ProfileId from User where isActive = TRUE and Profile.UserLicense.LicenseDefinitionKey = 'SFDC' and Id in (SELECT UserID FROM UserPackageLicense WHERE (PackageLicenseId= '050800000004xiQ'))]; pf = [Select Id, Name from Profile where Name = 'System administrator' or Name = 'Standard Security']; if(userList.size() > 0){ for(User u: userList){ if(trigger.isUpdate && u.Profile.Name != pf.Name && oldMap.get(u.id).ProfileId != u.ProfileId){ u.addError('Only system Administrator and security has access to edit profiles'); } } } } }Please correct me as I'm gettin the exception error while updating the profile as below:
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger UserTrigger caused an unexpected exception, contact your administrator: UserTrigger: execution of BeforeUpdate caused by: System.QueryException: Non-selective query against large object type (more than 200000 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): ()
You could try filtering for more restrictive fields to get less records or use for example limit 200000 at the end of the query.
[Select Id, Profile.Name, ProfileId from User where isActive = TRUE and Profile.UserLicense.LicenseDefinitionKey = 'SFDC' and Id in (SELECT UserID FROM UserPackageLicense WHERE (PackageLicenseId= '050800000004xiQ')) LIMIT 200000];
if it helps please like and mark as correct as it may help others with the same error.
Hi,
I tried that as well but still the same error.
You can try out in this way.
And le me know if it works for you.
Regards,
Surojit