• Pathak 1
  • NEWBIE
  • 15 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 6
    Replies
We have Communities Set Up and thus Community user.

The requirement is , If A Checkbox on Contact is Checked then , It should Update the Profile of that COmmunity User.

I am using below trigger - 
 
trigger AssignPermissionSet on Contact (after Update){
Set<ID> usersId = new Set<Id>();
Set<Id> contactIdsSet = new Set<Id>();
for (contact c :trigger.new) {
    if(c.Is_SUper_User__c == true) {
       contactIdsSet.add(c.Id);
    }
}
For(User usr : [Select Id From User Where ContactId!=null AND ContactId IN : contactIdsSet]){
	usersId.add(usr.Id);
}
  AssignCustomProfile.assignProfileToUser();
}

and Class Method -
 
public class AssignCustomProfile {

    public static void assignProfileToUser () {
        
        profile p = [SELECT ID FROM profile WHERE name='Custom12'];
        user u = new user(profileID = p.Id);
        update u;
    }
}

However not doing anything
HI , We have Community set up in our org. My req is if a Particular Checkbox is checked on a Contact then It should assign a Permission set to that Community user.

I have written below code but it throws MIXED DML EXCEPTION - 

   
trigger AssignPermissionSet on Contact (after Update)

    {
    
for (contact c :trigger.new) {
        if(c.Is_SUper_User__c == true) {
            
            user u = [SELECT ID from User WHERE ContactId = :c.Id];
            
            PermissionSetAssignment  psa = new PermissionSetAssignment 
            (PermissionSetId = 'XXXXXXXXXXXc94', AssigneeId = U.Id);
            insert psa;
            
        }
    }
}
I have heard to resolve this we have to use Future annotation, But can someone help with the class how should I accomplish this?
 
We have Communities Set Up and thus Community user.

The requirement is , If A Checkbox on Contact is Checked then , It should Update the Profile of that COmmunity User.

I am using below trigger - 
 
trigger AssignPermissionSet on Contact (after Update){
Set<ID> usersId = new Set<Id>();
Set<Id> contactIdsSet = new Set<Id>();
for (contact c :trigger.new) {
    if(c.Is_SUper_User__c == true) {
       contactIdsSet.add(c.Id);
    }
}
For(User usr : [Select Id From User Where ContactId!=null AND ContactId IN : contactIdsSet]){
	usersId.add(usr.Id);
}
  AssignCustomProfile.assignProfileToUser();
}

and Class Method -
 
public class AssignCustomProfile {

    public static void assignProfileToUser () {
        
        profile p = [SELECT ID FROM profile WHERE name='Custom12'];
        user u = new user(profileID = p.Id);
        update u;
    }
}

However not doing anything
HI , We have Community set up in our org. My req is if a Particular Checkbox is checked on a Contact then It should assign a Permission set to that Community user.

I have written below code but it throws MIXED DML EXCEPTION - 

   
trigger AssignPermissionSet on Contact (after Update)

    {
    
for (contact c :trigger.new) {
        if(c.Is_SUper_User__c == true) {
            
            user u = [SELECT ID from User WHERE ContactId = :c.Id];
            
            PermissionSetAssignment  psa = new PermissionSetAssignment 
            (PermissionSetId = 'XXXXXXXXXXXc94', AssigneeId = U.Id);
            insert psa;
            
        }
    }
}
I have heard to resolve this we have to use Future annotation, But can someone help with the class how should I accomplish this?