Apex Keywords

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.

  1. Class: This keyword is used to define/declare a class.
  2. Abstract: This keyword is used to define/declare a abstract class. An abstract class that contains abstract methods and non-abstract methods.
  3. 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.
  4. Extends: Defines a class that extends another class, which means a child class can extends a parent class using extends keywords.
  5. 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.
  6. Implements: Apex implements keyword is used to implement an interface.
  7. 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.
  8. Final: This keyword is used to define constants and methods that can’t be overridden within the child class.
  9. This: This keyword represents the current instance of a class , in constructor chaining.
  10. Super: This keyword invokes a constructor on a superclass.
  11. Return: This keyword returns a value from a method.
  12. 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.
  13. Null: This keyword defines a null constant that can be assigned to any variable so that it removes the garbage value.
  14. Public: Apex public keyword is an access modifier. It is used to indicate that an item is accessible anywhere with the Salesforce environment.
  15. 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.
  16. With sharing & Without sharing keywords
  17. 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.

Subscribe Now