Apex Objects - Apex

What is an Object?

The instance of class is called Object. According to Salesforce, object could be of class or you could create an object of sObject as well.

Object creation from Class

The object of class can be created as in Java or other object oriented programming language.
The below example shows Class called MyClass:

  • Instance class can call or access the variables or methods of this class.
  • Instance of the class is created and then all the operations can be done.

sObject creation

sObjects are the objects of Salesforce in which you can store the data.
For example, Account, Contact, etc. are custom objects. You could create object instances of these sObjects.

The below example shows the initialization of sObject and how the field of that particular object using dot notation can be accessed and assign the values to fields.

Static Initialization

When a class is loaded Static methods and variables are initialized only once.The Static variables aren't transmitted as part of the view state for a Visualforce page.

The below example shows the Static method and Static variable.

Static Variable Use

The Static variable value will be same within same execution context and any class, trigger or code which is executing could refer it and prevent the recursion.
The Static variables will be instantiated only once when class is loaded to avoid the trigger recursion.

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Apex Topics