This error, in respect to standard library methods, is always a result of name shadowing, assuming you have the correct parameters; the only other time you should get this error is if you have the wrong number or data types of parameters (e.g. passing in a String when an Integer is expected).
Basically, you have either a variable, class, or interface named UserInfo
(case insensitive) in the org where you're having the problem. The fix is to either (a) refactor or remove the UserInfo
class/variable/interface so it's no longer conflicting, or (b) use System.UserInfo.getUserName()
instead, which is always guaranteed to reference the library method, since System
is a reserved keyword.
As a matter of practicality, I advise refactoring over using the System
namespace, because this is likely to come up over and over again as more developers work on your code.