0

I’m going through preparation for a professional assessment and at the moment I have a question that I can’t give a complete answer to, as I am new to Apex.

Question: Describe the features of static methods. What methods(necessarily) must be static?

There are no problems with the first part, but I would like to find an exhaustive answer somewhere in the second part. Annotations @ Future for example, etc.

1 Answers1

0

static methods need to be used when you don't need an instance of a class or if the method needs to be exposed to other callers. Examples of this are lwc/aura/visualforce remoting methods.

See these links for examples of why static is necessary

https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/controllers_server_apex.htm

https://developer.salesforce.com/docs/component-library/documentation/lwc/lwc.apex

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_annotation_RemoteAction.htm

TemporaryFix
  • 2,008
  • 3
  • 30
  • 54
  • Oh, thank you very much for the information. It is really useful. Are there any other options, where "static" is necessary for methods? – Андрей Aug 02 '19 at 15:56
  • it really comes down to design patterns/architecture. `static` is not just an apex modifier. I'd implore you to look at the more general question on when to use `static`. This might be useful https://stackoverflow.com/questions/2671496/java-when-to-use-static-methods – TemporaryFix Aug 02 '19 at 16:12
  • Yes,ofc. Thank you – Андрей Aug 05 '19 at 07:27