[SalesForce] Possible to use runAs in Apex Trigger

Is it possible to use system.runAs() methods in a trigger? If it possible please provide sample code.

Best Answer

This method can only be used in tests. You can find the documentation for System.runAs here. Its documentation says:

All of the specified user's record sharing is enforced during the execution of runAs. You can only use runAs in a test method. For more information, see Using the runAs Method.

Related Topic