You need to sign in to do that
Don't have an account?

how to populate userinfo.username in testmethod?
Hi,
I have a before insert trigger to execute when a case is logged from selfservice portal.
It works fine but I have a problem of passing the test.
In the trigger:
ID contactId = [select contactId from SelfServiceUser where username=:UserInfo.getUserName()].contactId;
Then in the testmethod how to prepopulate the value to UserInfo.getUserName(), so the test can pass?
I have a before insert trigger to execute when a case is logged from selfservice portal.
It works fine but I have a problem of passing the test.
In the trigger:
ID contactId = [select contactId from SelfServiceUser where username=:UserInfo.getUserName()].contactId;
Then in the testmethod how to prepopulate the value to UserInfo.getUserName(), so the test can pass?
There are more details on test methods and runAs specifically on this recent wiki article: http://wiki.apexdevnet.com/index.php/An_Introduction_to_Apex_Code_Test_Methods
According to my test, the Userinfo can capture the information from both selfservice user and SF user.
The testmethod has to run as SF user.
Message Edited by dawnzdy on 01-08-2009 06:39 AM