+ Start a Discussion
ManjunathManjunath 

Creating a user record and profile in test class, is it possible?

Hi,

 

1.Can I create a virtual user recod and profile in my test class.

 

Regards,

Manjunath

Best Answer chosen by Admin (Salesforce Developers) 
harsha__charsha__c

Hi Manjunath,

 

You can create an user but you need to query the required profile according to the requirement..!

 

 

All Answers

harsha__charsha__c

Hi Manjunath,

 

You can create an user but you need to query the required profile according to the requirement..!

 

 

This was selected as the best answer
Jason Liveston 8Jason Liveston 8
Below is an example of creating a user.  
 
Profile profileId = [SELECT Id FROM Profile WHERE Name = 'Standard User' LIMIT 1];
        
     	User usr = new User(LastName = 'LIVESTON',
                           FirstName='JASON',
                           Alias = 'jliv',
                           Email = 'jason.liveston@asdf.com',
                           Username = 'jason.liveston@asdf.com',
                           ProfileId = profileId.id,
                           TimeZoneSidKey = 'GMT',
                           LanguageLocaleKey = 'en_US',
                           EmailEncodingKey = 'UTF-8',
                           LocaleSidKey = 'en_US'
                           );


 
Abhishek S 21Abhishek S 21
Is it possible to create without quering ?
 
keyur nandaniyakeyur nandaniya
Is it possible to assign that created profile to that user virtualy for test class if YES then HOW
Thanks.