Because User Mode database operations don't work for the Automated Process User, I need to litter my code with checks to see if the current user is such a user.
I've previously got an automated process user ID with the following:
return [SELECT Id FROM User WHERE IsActive = TRUE AND UserType = 'AutomatedProcess' AND Username LIKE '%autoproc%' LIMIT 1].Id;
I don't know if there can be more than one such user, but I'm going to change to use something like this:
Boolean isAutoProc = [SELECT Id
FROM User
WHERE Id = : UserInfo.getUserId()
AND Usertype = 'AutomatedProcess'].size() > 0;
Of course, rather than litter my code I'll likely refactor to put a wrapper around all database operations (queries and DML ops), but what I want to check is whether this approach is legitimate or whether I'm missing some key piece of information?