Skip to content

Instantly share code, notes, and snippets.

@atulgupta31
Created April 30, 2016 19:27
Show Gist options
  • Save atulgupta31/845eae93a2c6547a03c0f6cefd807903 to your computer and use it in GitHub Desktop.
Save atulgupta31/845eae93a2c6547a03c0f6cefd807903 to your computer and use it in GitHub Desktop.
//Fetch the Profile Id that will assigned to the user
List<Profile> profileList = [SELECT Id FROM Profile WHERE Name='Standard User'];
//Instantiate a user variable
User testUser = new User();
//if profilelist is not empty
if(!profileList.isEmpty()){
//Create user
testUser = new User(Alias = 'standt', Email='standarduser@testorg.com',
EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US',
LocaleSidKey='en_US', ProfileId = profileList[0].Id,
TimeZoneSidKey='America/Los_Angeles', UserName='standarduser@testorg.com');
//insert user
Database.insert(testUser);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment