Skip to main content
I was trying to insert a new user and got the folowing error:

 

System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [LastName, Email, Alias, TimeZoneSidKey, LocaleSidKey, EmailEncodingKey, ProfileId, LanguageLocaleKey]: [LastName, Email, Alias, TimeZoneSidKey, LocaleSidKey, EmailEncodingKey, ProfileId, LanguageLocaleKey]

 

what values shoul be given to 

 

TimeZoneSidKey, LocaleSidKey, EmailEncodingKey, ProfileId, LanguageLocaleKey

 

Apart from this can anyone suggest code to use the user details of existing user through apex code?
2 件の回答
  1. 2012年12月24日 13:38
    One way is to use an existing user while testing. see below:

     

     User u1 = [SELECT Id FROM User WHERE Alias='auser'];

     //Run As U1

     System.RunAs(u1){

     

    // your code here..

     

    }

     

     

    Other way is like you are trying to do:

     

     

    Try this:

     

    localesidkey='en_US'

    emailencodingkey='UTF-8'

    languagelocalekey='en_US'

    localesidkey='en_US'

     

     

    Get profile Id by:

     

    Profile p = [select id from profile where name='Standard User']; 

     

    and then use ProfileId = p.Id

     

     

    Hope this helps!!!