You need to sign in to do that
Don't have an account?
tmbarry
Need to pull an existing User Record
I am trying to create a test class for a new trigger and it involves a lookup to a user record. In my test class, do i have to create a new user entry, or is there a way to to reference any existing users in the org for the test?
Besides best practice:
If you put this on top of your test class (http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_annotation_isTest.htm):
isTest (seeAllData=true)
you can find users as normal:
[SELECT Id, Name FROM User Limit 1]
and use it as (http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_testing_tools_runas.htm):
System.RunAs(theUser) {
}
All Answers
Best practice is to create a new user record in your test class.
Besides best practice:
If you put this on top of your test class (http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_annotation_isTest.htm):
isTest (seeAllData=true)
you can find users as normal:
[SELECT Id, Name FROM User Limit 1]
and use it as (http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_testing_tools_runas.htm):
System.RunAs(theUser) {
}
Thanks Andries - I'll give that a try.