Monday, August 27, 2012

Salesforce: Creating user for testing / test methods

                Sometimes we have to crate user objects in tests & test methods. To crate a user we have to select a profile and set the required fields in the user objects as the apex code below.

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

    User testUser = new User(alias = 'u1', email='u1@testorg.com',
            emailencodingkey='UTF-8', lastname='Testing', languagelocalekey='en_US',
            localesidkey='en_US', profileid = pfl.Id,  country='United States', CommunityNickname = 'u1',
            timezonesidkey='America/Los_Angeles', username='u1@testorg.com');

No comments:

Post a Comment