+ Start a Discussion
Siva SakthiSiva Sakthi 

how to get the newly inserted user id


Using this below code able to create the user successfully.' I want to get the newly inserted user Id Immediately '  .Once again we put the query to get a user id or Is any way to get the user id. how to get this . Using Userinfo.getUserId() we can get current loged in user. Please guide me to achive this .

        Profile p = [SELECT Id FROM Profile WHERE Name='Standard User'];

        User u = new User(Alias = 'standt', Email='standarduser@testorg.com',
            EmailEncodingKey='UTF-8', LastName='Testing123', LanguageLocaleKey='en_US',
            LocaleSidKey='en_US', ProfileId = p.Id,
            TimeZoneSidKey='America/Los_Angeles', UserName='standarduserTestUser@testorg.com'); 
        insert u;
Advance Thanks
Mark Lewis 21Mark Lewis 21
Hello Maheswar

To get the User ID of the recently inserted user you simply invoke the u.id property if im not mistaken.

Hope this helps
Siva SakthiSiva Sakthi
Thanks. My requirement is i have lookup relationship (user) in customer object. I want to update the Customer object fields with this user id . Also assign the user first name and last name into  the customer first and last name. how can achive this share any sample code.