Skip to content

Instantly share code, notes, and snippets.

@oscartcy
Created June 2, 2015 06:51
Show Gist options
  • Select an option

  • Save oscartcy/fb292f02608ae7e81bf5 to your computer and use it in GitHub Desktop.

Select an option

Save oscartcy/fb292f02608ae7e81bf5 to your computer and use it in GitHub Desktop.
future method does not support list of objects flatten to string to pass complex data structure Also avoid breaking all batch DML operation with a flag
@future
// future method does not support list of objects, so we are going to use
// so tweak method in order to pass necessary info to create new PermissionSetAssignment
private static void createPermissionSetAssignments(List<String> createData) {
List<PermissionSetAssignment> insertPSAs = new List<PermissionSetAssignment>();
for(String data : createData) {
String[] ids = data.split(';');
PermissionSetAssignment psa = new PermissionSetAssignment(
PermissionSetId = ids[0],
AssigneeId = ids[1]
);
insertPSAs.add(psa);
}
try {
// set second param as 'false' to continue batch DML even though one of the DML throws exception
Database.insert(insertPSAs, false);
} catch (DmlException e) {
System.debug(e.getMessage());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment