I'm writing a test class on Opportunity which is testing trigger which execute on update. I've simple questions- I'm trying to print user which has created opportunity in this test class.
I'm using system.RunAs with system admin user but still code is not printing any user.This is the line in code i'm talking about
System.debug('CreatebyUSer=' + opp.createdbyID); //
My trigger basically find , if opp is created by some particular profile say system administrator then some fields need to be updated. How can I test trigger , if my test class doesn't give me user who has created the opportunity
Code is this :
@ isTest
public class OpportunityTest
{
static opportunity opp = new Opportunity();
static void PrePareTestData()
{
opp.Name = 'TestOpp';
opp.StageName = 'Prospecting';
opp.CloseDate = date.today();
}
testMethod Static void FuncOppTriggerTest()
{
PrePareTestData();
Test.startTest();
User u = Grp1_CreateUser.Adminuser();
system.debug('Current User=' + u);
system.runAs(u)
{
insert opp;
opp.stageName = 'Qualification';
update opp;
System.debug('CreatebyUSer=' + opp.createdbyID); // This is coming as null
}
Test.stopTest();
System.assertEquals(opp.NextStep, 'Opp to move to next step');
}
}