• #26795
    Salesforce | Ankit Ankit #952
    Forcetalks

    How to create a User through Salesforce Apex?

    I wanted to created a user using apex, how can be done?

     

    #26797
    Salesforce | PRANAV PRANAV #958
    Forcetalks

    Hi Ankit,

    The below code will help you, but before running the code please check the required field on User Object, so that you need to include those also.

    Profile p = [SELECT Id FROM Profile WHERE Name=’System Administrator’ limit 1];
    list<User> usr = new list<User>();
    User u = new User(Alias = ‘st’, Email=’[email protected]’,
    EmailEncodingKey=’UTF-8′, LastName=’ABC’, LanguageLocaleKey=’en_US’,
    LocaleSidKey=’en_US’, ProfileId = p.Id , CustomUserName__c = ‘Test name’,
    TimeZoneSidKey=’America/Los_Angeles’, Username=’[email protected]’,
    CommunityNickname = ‘Test’);
    usr.add(u);
    insert u;

    Hope this helps you.

    #26800
    Salesforce | Adarsh Adarsh #959
    Forcetalks

    Hi ankit,

    Profile p = [SELECT Id FROM Profile WHERE Name=’System Administrator’ limit 1];

    User u = new user();
    u.LastName = ‘Test Code Welcome’;
    u.Email = ‘[email protected]’;
    u.Alias = ‘Tcode’;
    u.Username = ‘[email protected]’;
    u.CommunityNickname = ‘test1211’;
    u.LocaleSidKey = ‘en_US’;
    u.TimeZoneSidKey = ‘GMT’;
    u.ProfileID = p.id;
    u.LanguageLocaleKey = ‘en_US’;
    u.EmailEncodingKey = ‘UTF-8’;
    insert u;

    #26877
    Salesforce | Archit Archit #957
    Forcetalks

    User u = new user();
    u.LastName = ‘Test Code’;
    u.Email = ‘[email protected]’;
    u.Alias = ‘Tcode’;
    u.Username = ‘[email protected]’;
    u.CommunityNickname = ‘test12’;
    u.LocaleSidKey = ‘en_US’;
    u.TimeZoneSidKey = ‘GMT’;
    u.profileId = ’00e28000001Xsf3′;
    u.LanguageLocaleKey = ‘en_US’;
    u.EmailEncodingKey = ‘UTF-8’;
    insert u;

Viewing 4 posts - 1 through 4 (of 4 total)

Please to reply to this topic.

CONTACT US

We're not around right now. But you can send us an email and we'll get back to you, asap.

Sending

About Us

Forcetalks is a Salesforce collaboration platform for coders & developers, geeks & nerds, consultants & business heads, admins & architects, managers & marketers and of course the business owners. A community where you can learn from, where you can contribute to. For you. For Salesforce. Read More...

Copyright 2020 Forcetalks. All Right Reserved.

Log in with your credentials

or    

Forgot your details?