Delete Group using Apex
The reason that this is happening is because within your UninstallHandler, the user in context is a temporary user that is used when performing managed package operations. This user type is LicenseManager
. I'm assuming for security purposes, they do not have access to many dml operations on setup objects.
We tried a similar thing in our uninstall handler to remove our packaged permission sets from users. That also fails in the same way yours does.
I haven't tried it, but I assume that calls to @future
will either throw an exception, or be discarded because the uninstall process needs to run synchronously right before the actual uninstall.
According to this post, adding the without sharing
keyword may get this temporary user the appropriate permissions but obviously, without creating a package and testing DML on groups, it's hard to tell if it will work.