The this
keyword is used to identify the current instance of a class. Static functions do not run in an instance context so this
has no real meaning. If you want to call a static method from another static method in the same class, you use the name of the class instead of this.
Based on your comments, it seems that you're trying to call a non-static method from a static context. If you would like to call the instance method methodToValidate
from a static function, you first have to make an instance of the class. So in your static method you use something like this:
AuraSampleController sampleController = new AuraSampleController();
sampleController.methodToValidate(true);
It seems though that you're lacking basic understanding of the difference between static and instance functions. I suggest you read up on this, the Apex documentation regarding static and instance methods could be a good place to start. The static keyword in Apex has a lot in common with for instance Java's static, but there are differences, so keep that in mind when using documentation for a different language.
this
. So it looks likeMyClass.methodToValidate(true);
– rael_kid Sep 24 '18 at 5:42Non static method cannot be referenced from a static context: ApexPages.Message AuraSampleController.methodToValidate(Boolean)
– user59569 Sep 24 '18 at 5:43