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
Aman Verma 45Aman Verma 45 

Every New User is always active(checkbox is tick). Can we create a user as Inactive?

Best Answer chosen by Aman Verma 45
Maharajan CMaharajan C
Hi Aman,

By Clicking the new user from UI it's not possible.

It's default checked as True by Salesforce.It's Standard field so it's not possible to edit property of that field

But you can use the Apex to insert the record as Inactive user i tried now it works . Try to execute the  below code using devconsole or workbench.
Also try yourself with Process builder because i didn't tried to create the user by PB.

List<User> userList = new List<User>();
    List<Profile> profileList = [Select Id from Profile where Name=: 'System Administrator' limit 1];
    List<UserRole> roleList = [Select Id from UserRole where Name=: 'CEO' limit 1];
        User uObj = new User();
        uObj.LastName = 'MahaRaj';
        uObj.Username = 'maharajancm@gmail.com';
        uObj.Email = 'maharajansfdc@gmail.com';
        uObj.Alias = 'mc';
        uObj.UserRoleId = roleList[0].Id;
        uObj.ProfileId = profileList[0].Id;
        uObj.IsActive = true; 
        uObj.TimeZoneSidKey = 'GMT';
        uObj.LanguageLocaleKey = 'en_US';
        uObj.EmailEncodingKey = 'UTF-8';
        uObj.LocaleSidKey = 'en_US';
        uObj.IsActive = False ;
        userList.add(uObj);
    
    insert userList;  

Can you please Let me know if it helps or not!!!

If it helps don't forget to mark this as a best answer!!!


Thanks,
Raj
 

All Answers

bhanu_prakashbhanu_prakash
Hi Aman
Mark as best answer, If it resloves !!
Please check these link
https://automationchampion.com/2015/06/11/getting-started-with-process-builder-part-28-auto-freeze-users-account/

Mark as resloved if it helps :) :)
Thanks, 
Bhanu Prakash
visit ForceLearn.com  ​  (https://www.forcelearn.com/)
Maharajan CMaharajan C
Hi Aman,

By Clicking the new user from UI it's not possible.

It's default checked as True by Salesforce.It's Standard field so it's not possible to edit property of that field

But you can use the Apex to insert the record as Inactive user i tried now it works . Try to execute the  below code using devconsole or workbench.
Also try yourself with Process builder because i didn't tried to create the user by PB.

List<User> userList = new List<User>();
    List<Profile> profileList = [Select Id from Profile where Name=: 'System Administrator' limit 1];
    List<UserRole> roleList = [Select Id from UserRole where Name=: 'CEO' limit 1];
        User uObj = new User();
        uObj.LastName = 'MahaRaj';
        uObj.Username = 'maharajancm@gmail.com';
        uObj.Email = 'maharajansfdc@gmail.com';
        uObj.Alias = 'mc';
        uObj.UserRoleId = roleList[0].Id;
        uObj.ProfileId = profileList[0].Id;
        uObj.IsActive = true; 
        uObj.TimeZoneSidKey = 'GMT';
        uObj.LanguageLocaleKey = 'en_US';
        uObj.EmailEncodingKey = 'UTF-8';
        uObj.LocaleSidKey = 'en_US';
        uObj.IsActive = False ;
        userList.add(uObj);
    
    insert userList;  

Can you please Let me know if it helps or not!!!

If it helps don't forget to mark this as a best answer!!!


Thanks,
Raj
 
This was selected as the best answer
Aman Verma 45Aman Verma 45
Thank you!!!