I wrote an apex service (called by my Account Trigger
before insert and
before update) that runs some complex validation , and it starts by querying for the user record of the running user since the validation needs to know their UserRole as well as some custom User field values:
Id runningUserId = UserInfo.getUserId(); User runningUser = [SELECT Id, UserRoleId, Custom_fields__c FROM User WHERE Id = :runningUserId LIMIT 1];
I shipped this service to production today and had no issues. Until just now, when (11:15 PM) I got a Developer Script Exception email with the error
System.QueryException: List has no rows for assignment to SObject on my second line of the code above.
When I took the User id in the exception email and plugged it into the URL bar, I got insufficient privileges. I am a system admin, so it seems that this code execution was run by a user that does not correspond to any actual User record in my org.
I've tried googling "Salesforce system user" but haven't found anything useful. Is there some kind of root system user or something that can edit records or execute code?