function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Adila Hilal 9Adila Hilal 9 

Grant Login Access to User as System admin Using Flows and process builder

Hello,

We have a requirement where I have to automate a process to assign login access to user as System Admin and after Expiration date the profile should automatically be revoked to original. I have used process builder and a flow just to update profileId with Oriinal.Somehow the flow is not working as the expiration date passes the Profile doesnt revert back to original.So I am trying to write apex code to invoke a method from process builder. This s what I am trying to do.Please need help in writing code.
trigger updateUserProfileTrigger on User (after insert, after update) {
    
 public class updateUserProfile {

 public static ID profile1;
 public static ID profile2;
  
  @future
    
    public static void assignProfileToUser(  for [profile p: [SELECT ID ,Name FROM Profile]){
           if(p.name == 'System Administrator'){
               profile1 = p.id;
           } else if(p.name == 'Last_Profile_Id'){
               profile2 = p.id;
            }
       }       for (User u : userListNew) {
           if (u.User_Admin__c == true) {
               user u = userMap.get(u.id);
               u.profileID = profile1;                        

                u.profileID = profile2;
               usertoUpdate(u);
           }
           
       }