Apex is a strongly typed, object-oriented programming language that allows developers to execute flow and transaction control statements on the Salesforce platform. It uses syntax that looks like Java and acts like database stored procedures.
An Apex class typically follows this structure:
[access_modifier] class ClassName { // Properties // Methods }
Access modifiers in Apex determine the visibility of your classes, methods, and variables:
In Apex, properties store values and can be accessed by other parts of your code. Variables declared inside methods have limited scope.
public class Person { // Property public String name; // Method with a local variable public void greet() { String greeting = 'Hello ' + name + '!'; System.debug(greeting); } }
Constructor methods initialize a new instance of a class. They have the same name as the class and don't specify a return type.
public class Person { public String name; // Constructor public Person(String initialName) { this.name = initialName; } }
Sign up to track your progress, earn points, and compete with others. Your solutions will be saved automatically.
Create account