How to revoke Oauth token for inactive users in Salesforce

2:17 PM

After a user has been deactivated you might notice in the LoginHistory that previously authenticated apps are trying to establish a login resulting in login failure.

This will show up in Scale Center under 'Failed Logins'. To remove these failures you can revoke the apps for these inactive users. You can do this for individual users by going to Setup -> Users -> User Detail -> Oauth Apps -> Revoke


When you have to do this for hundreds of users, it isn't effecient to do this manually. You can run the below script in anonymous apex. To further automate, you might want to schedule this as a batch class to run weekly or daily.