Yes we can use RunAs with in Dynamics ax code also, sometime we need to run specific operation under different user account, for that purpose we can use RunAs to execute particular method or operation based on that new user.
Syntax to use the RunAs
Runas(UserAccountId, ClassId, StaticMethod, methodName, ContainerParms)
Calling method: If you see this implementation, we must need to have the runAs method having parameter of type container. So before calling this method we need to add all needed inputs to the container and pass the container as arguments.
In this example we are generating outbound file using Runas method under different account.