I have a test class, with this code
System.debug(UserInfo.getProfileId());
Profile p = [SELECT Id FROM Profile WHERE Name = 'Standard User'];
User u = new User(ProfileId = p.Id, ...);
System.runAs(u)
{
System.debug(UserInfo.getProfileId());
Database.delete(records, false);
}
In the trigger handler that fires for this DML operation, when I output the current user`s Id
System.debug(UserInfo.getProfileId());
It does not get the Profile Id of the User that I set in the System.runAs method. It gets the Profile Id of the User... me, ie. the System Administrator, when it should be the Standard User.
Why?... And how to fix?