we have a scenario where we are refreshing the org and have taken up the backup of users, permission set assignment, and their public group. After the refresh, the task is to upload the backup data, which is in excel format, again into the org post the refresh work. The backup excel consists of users, their basic details, and more importantly their assigned permission sets and public groups, which can be more than one entry in an excel cell for a user, separated by a comma, like in the image below.

Sample data imahe

I've created a script which has a list of User standard object and basic user details manually fed to that list, which just inserts the record of the users. Now I have to create a script or two, to update the permission set assignment and group membership of each user according to excel.

Is there any way I can do this task through apex where I can load the data from excel and loop through it picking up PSA and Groups for each user and then assign that to the respective user again?

This has to be done through apex scripting only where the scripts will be directly run so also can't make any method calls too. Can be done using brute force and manual effort but since this refresh thing happens often thus a script that extracts the details from excel and update in the org will help a lot.

Fairly new to salesforce so bear with me please. :)

2 Answers 2


There is no need to reapply PermissionSetAssignment because they should remain intact during sandbox refresh.

That is to say, after refresh the sandbox should still have its users, permission sets, and permissionSetAssignment. The users email will be purposefully broken, but you can edit it for the users needing access..

( That said, you can use dataloader on psa by providing PermissionSetID and AssigneeId)


You can use a class extending sandboxpostcopy interface. Put all your setup routines in there. Have it run automatically on sandbox create/refresh.

This excel file save as csv, and load up in resources. Then read it from the postcopy class and do all of your queries and updates.

Can also spin up a lot of async @future methods from the postcopy class, if you start hitting governor limits.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .