• Viswanath Yarramala
  • NEWBIE
  • 0 Points
  • Member since 2020
  • Salesforce Developer
  • Neeha It Services Pvt Ltd


  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
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?