I have a visualforce page that creates a record, and then assigns a permission set to the User and updates some of the fields on the user.
The update for the Permission Set Assignment needs to be a future method. However, I can't get the page to reload when the future method is complete.
Are there any design patterns for VisualForce that uses a future method and then populates a table with the result after its finished.
@Future
public static void setPermissionSet(Id userId, String permissionSetName) {
PermissionSet ps = [SELECT Id FROM PermissionSet WHERE Name = :permissionSetName LIMIT 1];
// Create a PermissionSetAssignment record to assign the permission set to the user
PermissionSetAssignment psa = new PermissionSetAssignment();
psa.AssigneeId = userId;
psa.PermissionSetId = ps.Id;
// Insert the PermissionSetAssignment record
insert psa;
}
I call this from a save method in the controller class.
public void save(){
System.debug('SAVING');
Savepoint sp = Database.setSavepoint();
try{
checkEmailOption();
insert con;
ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.CONFIRM, 'SUCCESS: You have commissioned ' + [SELECT Id, Name FROM Contact WHERE Id =: this.c.Id].Name);
ApexPages.addMessage(myMsg);
this.conTypes = GetConTypes();
if (assignPermInput == true && emailOption!=ADF_Utilities.defaultValue) {
updateUser();
}
checkFuture();
this.psa = getPermissionAssignments();
this.con = new Classification_Type_Contact__c(Contact__c = this.c.Id );
} catch (Exception e){
System.debug(e.getMessage());
ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR, 'Oops... ' + e.getMessage());
ApexPages.addMessage(myMsg);
Database.rollback(sp);
}
}