0

We have an event trigger that's throwing an error for 1 specific user. We've tested with similar users that have: same assigned profile and role and license and we tried creating the meeting on the same accounts. It works for others but not this one specific user.

This is the error when the one user attempts to save a meeting:

Validation Errors While Saving Record(s) There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was Apex trigger ActivityTrigger caused an unexpected exception, contact your administrator: ActivityTrigger: execution of BeforeUpdate caused by: System.QueryException: List has no rows for assignment to SObject: Trigger.ActivityTrigger: line 8, column 1.

Click here to return to the previous page.

This is the line 8 thats causing the issue; it's just a SOQL call to get a system user id :

ID DataAdmin = [Select id from User where name = 'Data Admin' limit 1].id;

Any ideas why only this user retrieves an empty list when looking up this user account? I am able to put in the static id and that does work.

  • Do you have Data Admin user in system? – Rohit Mourya Jul 19 '17 at 12:30
  • What are your security Settings for User object? Maybe this user's profile permissions are different from the others and therefore can't query on other users since it can't find them. We should also know what is your concern, being able to return the results on the query for this user or avoiding getting the error on the query. – Alexander Aeons Torn Jul 19 '17 at 12:39
  • @RohitMourya Yes we do have Data Admin in the system. – user47343 Jul 19 '17 at 13:31
  • @AlexanderAeonsTorn Security Settings for User is public read-only. I've used test users that have the same profile. It just doesn't work for this 1 user. My concern would be making sure we get results for the query as the id is used later on in the trigger. Putting in the ID statically is my best bet for now it seems but i'm really curious why this doesn't work for this user. – user47343 Jul 19 '17 at 13:33
1

I would suggest to bulkify a query like this:

List<User> users = [Select id from User where name = 'Data Admin' limit 1];
if ( users.size() > 0 ) {
   ID DataAdmin = users[0].Id;
}

In such case you won't receive error even if your user sharing settings do not allow him to access Data Admin user record.

======

Also, user locale setting might matter. Because in different language you might have different separator between First Name and Last Name and the query might be different like Data|Admin instead of Data Admin, so you might try to query upon LastName or change user locale or language.

  • This is a fair way to code that portion but my concern is more making sure we have an id no matter what as it is used later in the trigger. When you say User sharing settings do you mean org-wide settings? currently User is set to public read-only for us. – user47343 Jul 19 '17 at 13:35
  • 1
    Yes, I mean OWD and Record-level security. It is strange then. Maybe this user has some different locale or language or maybe this user can't access name field? Did you try to rewrite your query to query upon LastName and FirstName instead of Name field? – Patlatus Jul 19 '17 at 13:48
  • Bingo Patlatus! I tried LastName field only and the error stopped occurring for the problem user. So it meant it probably was some locale issue and it was! He was set to use Japanese (Japan) ; i changed it to English (United States) and it started working even with the original 'Name' field query as well for the problem user. It never occurred to me that locale would affect a query like this; very interesting. – user47343 Jul 19 '17 at 14:13
  • yes, it can. Because in Japanese language you might have different separator between First Name and Last Name and the query might be different like Data|Admin instead of Data Admin – Patlatus Jul 19 '17 at 14:16
  • 1
    Just had this issue and wanted to add that for me, it was the fact that some Asian locales represent the Name field as LastName + FirstName, not the western way of FirstName + LastName. Pretty stupid that triggers, which run in system context, perform queries which respect the running user's locale! – ministe2003 Jul 28 '17 at 9:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.