+ Start a Discussion
Internal PartnerInternal Partner 

Needed help by improving Apex code for invoking the ObfuscateUser(UserId, Username) method

Hi all,

I am trying to create some code in order to invoke the obfuscateUser method, which anonymize user data, when users for example leave a company (GDPR compliance).

There is the following code:
 
public class UserManagementController{
    public List <User> users {get; set;}
    
    public UserManagementController()
    {
        Profile p = [select id from profile where name = 'Customer Community User'];
        
        users = [select username, id from User where profileId=:p.id AND isactive=true];
    }
    
    static public void obfuscate(User users)
    {
        
        //User u = [select contactId from user where id=:uid];
        
        System.UserManagement.obfuscateUser(users.id);
        
        
    }
}
Perhaps I want to use the username as well in order to anonymize or obfuscate the user and I don't want to use hard coding such as mentioning a specific profile in the code like in the example above. Ca somebody guide me how can I improve this code, so I can invoke it from the Developer Console?.

Any help will be appreciated.