Print this page

Time Limit Exceeded when adding all the classes to the profile

Knowledge Article Number 000182094
Description When adding All the classes to a Profile, at times the request takes too long and fail with "Time Limit Exceeded" error.
Resolution As a workaround when we have too many classes to be added to a profile, we can add them to Permission Sets that are not owned by a Profile.
So the workaround is to create a new Permission Set that includes all the classes and then apply it to the appropriate users. This can be done via the UI & API / Workbench.


Step 1 
====== 
1. Create a new Permission Set in the UI (Setup > Manage Users > Permission Set) 
2. Get the ID of the new Permission Set either via the UI Address Bar, or by querying it: 

SELECT Id FROM PermissionSet WHERE Label = 'All Classes' 

Step 2 
====== 
Query and save the ids of the ApexClasses you want to grant access for into a CSV: 

SELECT Id FROM ApexClass 

You can add a WHERE clauses to restrict result set for example: WHERE NamespacePrefix LIKE 'ff%' 

Step 3 
====== 
Once you have the list of apex class ids, create csv file with two columns, ParentId (which will be the permission set id obtained in step 1) and SetupEntityId (containing all the apex class id's obtained in step 2) -- the parent id will be repeated for each and every apex class that you want to grant access. It should look something like this: 
 
ParentIdSetupEntityId
0PSF0000000OvExOAK01p50000000U3weAAC
0PSF0000000OvExOAK01p50000000U3yJAAS
You can also include multiple permission set ids using the same csv, if you want to assign access to multiple permission sets. 

Step 4 
====== 
Once the csv file is ready, use workbench and the csv file to insert new SetupEntityAccess records. 
** Be sure to select "Process records asynchronously via Bulk API
** The bulk API will process batches of 200 records rather than one request that could timeout. 

Now we have added all the Apex classes to the permission set. Next step is to add this permission set to set of users.
Step 5 
====== 
Manually assign the permission set to users via the UI (User Record Page) 
OR 
Insert a PermissionSetAssignment Record for each User that is to have these permissions. 

The data would look something like this:        
AssigneeIdPermissionSetId
005F0000001Bzp7IAC0PSF0000000OvExOAK
005F0000001CqckIAC0PSF0000000OvExOAK
Once the csv file is ready, use workbench and the csv file to insert PermissionSetAssignment records in Bulk. 




promote demote