Apex keywords are also known as reserved words. Keywords are particular words which act as a key to a code. These are predefined words by Apex so it cannot be used as a variable or object name as per requirements.
- Class: This keyword is used to define/declare a class.
- Abstract: This keyword is used to define/declare a abstract class. An abstract class that contains abstract methods and non-abstract methods.
- Virtual: This keyword defines/declare a class or method that allows extension and overrides. We can’t override a method with the override keyword unless the class or method has been defined as virtual which means if a class is virtual then only that class allows extension and if method is virtual then allows overrides in sub class.
- Extends: Defines a class that extends another class, which means a child class can extends a parent class using extends keywords.
- Interface: Apex interface keyword is used to declare an interface. It can have only abstract methods. A class always implements an interface and an interface always extends another interface. Java implements keyword is used to implement an interface.
- Implements: Apex implements keyword is used to implement an interface.
- Static: This keyword defines a method/variable that is only initialized once at a class level, and it is associated with an (outer) class. We can call static variables/methods by class name directly. No need of creating instance of a class.
- Final: This keyword is used to define constants and methods that can’t be overridden within the child class.
- This: This keyword represents the current instance of a class , in constructor chaining.
- Super: This keyword invokes a constructor on a superclass.
- Return: This keyword returns a value from a method.
- Transient: This keyword declares instance variables that cannot be saved, and should not be transmitted as part of the view state in the visualforce controllers and extensions.
- Null: This keyword defines a null constant that can be assigned to any variable so that it removes the garbage value.
- Public: Apex public keyword is an access modifier. It is used to indicate that an item is accessible anywhere with the Salesforce environment.
- Global: Apex global keyword is an access modifier. It is used to indicate that the item is accessible anywhere. Which means within the Salesforce or outside the salesforce too, It has the widest scope among all other modifiers in Apex.
- With sharing & Without sharing keywords
With sharing Keyword: This keyword enforces the sharing rules of the org that apply to the current user. We usually called it user mode also.
Without sharing keyword: Ensures that the sharing rules of the org are not going to apply on current user. We usually called it system mode also.