> ## Documentation Index
> Fetch the complete documentation index at: https://docs.shiftupai.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Clearing profile permissions

In case the application was installed for `All Users` instead of `Only Administratos` , all custom profiles in the org will have incorrect permissions assigned for the ShiftUp app and we will need to clear those permissions. We have 2 options:

**1- (Recommended) Uninstall the package and start over with just the** `Install for Admins  Only `**option.**

This is the recommended option if you haven't started using ShiftUp as there is no data yet in the org. Follow the [Uninstalling ShiftUp](/setup/uninstalling-shift-up)  steps to complete this.

**2- Cleanup permissions and settings for custom profiles.**

Use this option an option other than `Install for Admins Option`was selected and you already have data created in the org.

Removing permissions and settings can be a laborious process, so we've written a script to help do this:

<Warning>
  DO NOT modify the contents of this script, this script is scoped to only affect components related to the ShiftUp package, modifying the contents of this script could lead to data loss in your environment.
</Warning>

<Check>
  IMPORTANT: By default this script runs a dryRun only, to run it write mode, change the line that says  `Boolean dry=true;` to `Boolean dry=false;`

  Additionally, the script updates profiles in batches of 3, so you will need to run this script several times and increment the `Integer start=0,size=3`  by 3. For example: `Integer start=3,size=3;` , then `Integer start=6,size=3;` , etc..
</Check>

```apex theme={null}
String n='tvggs',pre=n+'__';
Boolean dry=true;
Integer start=0,size=3;
List<PermissionSet> p=[SELECT Id,Profile.Name FROM PermissionSet WHERE IsOwnedByProfile=true AND IsCustom=true ORDER BY Profile.Name,Id];
for(Integer i=0;i<p.size();i++)System.debug('['+i+'] '+p[i].Profile.Name+(i>=start&&i<start+size?' *':''));
System.debug('TOTAL PROFILES: '+p.size());
if(start<0||size<1||start>=p.size())System.debug('INVALID RANGE');
else{
Set<Id> ps=new Set<Id>();
Map<Id,String> pn=new Map<Id,String>();
for(Integer i=start;i<Math.min(p.size(),start+size);i++)if(p[i].Profile.Name!='System Administrator'){
ps.add(p[i].Id);pn.put(p[i].Id,'['+i+'] '+p[i].Profile.Name);
}
Set<String> os=new Set<String>(),fs=new Set<String>(),md=new Set<String>();
Map<String,Schema.SObjectType> gd=Schema.getGlobalDescribe();
for(String o:gd.keySet()){
Boolean b=o.startsWith(pre);
if(b){os.add(o);if(o.endsWith('__mdt'))md.add(o);}
for(String f:gd.get(o).getDescribe().fields.getMap().keySet())
if(f.startsWith(pre))fs.add(o+'.'+f);
}
List<FieldPermissions> fl=new List<FieldPermissions>();
if(!ps.isEmpty()&&!fs.isEmpty())
for(FieldPermissions f:[SELECT Id,ParentId,Field,PermissionsRead,PermissionsEdit FROM FieldPermissions WHERE ParentId IN :ps AND Field IN :fs AND PermissionsRead=true]){
f.PermissionsRead=false;f.PermissionsEdit=false;fl.add(f);
}
List<ObjectPermissions> ob=new List<ObjectPermissions>();
if(!ps.isEmpty()&&!os.isEmpty())
for(ObjectPermissions o:[SELECT Id,ParentId,SObjectType,PermissionsRead,PermissionsCreate,PermissionsEdit,PermissionsDelete,PermissionsViewAllRecords,PermissionsModifyAllRecords FROM ObjectPermissions WHERE ParentId IN :ps AND SObjectType IN :os]){
if(!(o.PermissionsRead||o.PermissionsCreate||o.PermissionsEdit||o.PermissionsDelete||o.PermissionsViewAllRecords||o.PermissionsModifyAllRecords))continue;
o.PermissionsModifyAllRecords=false;o.PermissionsViewAllRecords=false;
o.PermissionsDelete=false;o.PermissionsEdit=false;
o.PermissionsCreate=false;o.PermissionsRead=false;ob.add(o);
}
Set<Id> ids=new Set<Id>(),apps=new Set<Id>(),other=new Set<Id>();
Map<Id,String> nm=new Map<Id,String>();
for(ApexClass a:[SELECT Id,Name FROM ApexClass WHERE NamespacePrefix=:n]){
ids.add(a.Id);nm.put(a.Id,'CLASS '+a.Name);
}
for(CustomPermission c:[SELECT Id,DeveloperName FROM CustomPermission WHERE NamespacePrefix=:n]){
ids.add(c.Id);nm.put(c.Id,'PERMISSION '+c.DeveloperName);
}
if(!md.isEmpty())for(EntityDefinition e:[SELECT DurableId,QualifiedApiName FROM EntityDefinition WHERE QualifiedApiName IN :md]){
String d=e.DurableId;
if(d!=null&&d.startsWith('01I')&&(d.length()==15||d.length()==18)){
Id x=(Id)d;ids.add(x);nm.put(x,'METADATA '+e.QualifiedApiName);
}}
for(AppMenuItem a:[SELECT ApplicationId,Label FROM AppMenuItem WHERE NamespacePrefix=:n AND Type='TabSet'])
if(a.ApplicationId!=null){
ids.add(a.ApplicationId);apps.add(a.ApplicationId);
nm.put(a.ApplicationId,'APP '+a.Label);
}
if(!ps.isEmpty()&&!apps.isEmpty())
for(SetupEntityAccess a:[SELECT ParentId,SetupEntityId FROM SetupEntityAccess WHERE ParentId IN :ps AND SetupEntityType='TabSet'])
if(!apps.contains(a.SetupEntityId))other.add(a.ParentId);
List<SetupEntityAccess> del=new List<SetupEntityAccess>();
if(!ps.isEmpty()&&!ids.isEmpty())
for(SetupEntityAccess a:[SELECT Id,ParentId,SetupEntityId FROM SetupEntityAccess WHERE ParentId IN :ps AND SetupEntityId IN :ids]){
if(apps.contains(a.SetupEntityId)&&!other.contains(a.ParentId))
System.debug('SKIP APP '+pn.get(a.ParentId)+' '+nm.get(a.SetupEntityId));
else del.add(a);
}
System.debug('DRY='+dry+' BATCH='+start+'-'+(Math.min(p.size(),start+size)-1));
System.debug('PROFILES='+ps.size()+' CRUD='+ob.size()+' FLS='+fl.size()+' ACCESS='+del.size());
System.debug('SOQL ROWS='+Limits.getQueryRows());
Integer total=ob.size()+fl.size()+del.size(),ok=0,err=0;
if(dry)System.debug('DRY RUN - NO CHANGES');
else if(total>Limits.getLimitDmlRows()-Limits.getDmlRows())System.debug('ABORT: REDUCE BATCH SIZE');
else{
if(!fl.isEmpty()){
Database.SaveResult[] r=Database.update(fl,false);
for(Integer i=0;i<r.size();i++){
if(r[i].isSuccess())ok++;
else{err++;for(Database.Error e:r[i].getErrors())
System.debug('FLS ERROR '+pn.get(fl[i].ParentId)+' '+fl[i].Field+' '+e.getMessage());
}}}
if(!ob.isEmpty()){
Database.SaveResult[] r=Database.update(ob,false);
for(Integer i=0;i<r.size();i++){
if(r[i].isSuccess())ok++;
else{err++;for(Database.Error e:r[i].getErrors())
System.debug('CRUD ERROR '+pn.get(ob[i].ParentId)+' '+ob[i].SObjectType+' '+e.getMessage());
}}}
if(!del.isEmpty()){
Database.DeleteResult[] r=Database.delete(del,false);
for(Integer i=0;i<r.size();i++){
if(r[i].isSuccess())ok++;
else{err++;for(Database.Error e:r[i].getErrors())
System.debug('ACCESS ERROR '+pn.get(del[i].ParentId)+' '+nm.get(del[i].SetupEntityId)+' '+e.getMessage());
}}}
System.debug('SUCCESS='+ok+' ERRORS='+err);
}}
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.