The whole Salesforce is divided into two modules: one module is salesforce admin, and another module is salesforce developer. Salesforce developer works on the Salesforce platform to develop custom applications. The regular activities of a salesforce developer include integrating the platform with other systems, Personalising the salesforce environment for a specific client. Salesforce developers work apex programming for front-end Development.

Define Apex

In Salesforce, Apex is an object-oriented programming language, and its syntax rules are similar to java. Apex Programming is available in a multi-tenant environment. Apex has in-built support for unit test execution and creation. 

Want to enhance your skills in dealing with the worlds best CRM, enroll in our Salesforce Training 

Working of Apex Programming

  • Developer work

The developer develops the apex code and compiles the code with the help of an apex runtime interpreter, and the developed code is stored as metadata to the platform.

  • End-user work

When the end-user incident implements apex code, the platform server takes the instructions from metadata and executes them with a runtime interpreter prior to the calculation of the result.

Different operations performed in the programmer console.

1. Developing and Compiling Code:

You can develop the code with any editor. When you store a class or a trigger, the code is executed automatically. If we get any errors, then they are reported.

2. Debugging

For Debugging also, we will follow the compilation Procedure.

3. Testing

After the Debugging Process is completed, we can see the debug logs and fix the checkpoints which help in debugging.

3. SOQL Queries

You can Monitor Debug logs to find out the performance obstacles.

4. Monitoring Performance

You can run tests of particular test classes, and you can see the test results.

Frequently asked Salesforce Interview Questions & Answers

Data Types in Apex Programming

Apex programming Supports different data types.

  • Primitive(Integer, Long, Double, Date, Boolean, etc.).
  • Collections
  • Enums
  • sObject
  • Classes

First, we will know about the Primitive Data type.

Primitive Data Types

The Primitive Data Types supported by Salesforce are as follows:

1. Integer

Integer Data Type is used when the variable takes integer values.

Subscribe to our youtube channel to get new updates..!

2. Boolean

Boolean Data Type is used when the variable takes only two input values, i.e. true or false.

3. String

The string data type is used when the variable has to store a group of characters.

4. Enum

Enum data type is used when the variable has to store one identifier from a limited set of identifiers. It is also called an abstract data type. 

Variables

A Variable is defined as a name given to a specific memory location in which we can store data or information. In apex programming, the variable declaration is the same as java. Example for variable declaration is as follows:

Integer a=10;

Scope of Variables

In Apex Programming, from the point of its declaration, a variable is valid. If a variable is declared in a method, then that variable is restricted to that method only. The variables which are declared in a class are used throughout that class.

Constants

Constants are also known as variables which do not change their value after assigning or after declaring.

Apex Classes

A class is a matrix or blueprint by which objects are generated. An object is a paradigm of a class. Apex classes are identical to java classes. Classes contain methods to do a specific task.

Example

Public class mindmajix
{

Code to be executed

}

Operators in Apex Programming

Apex Programming supports various types of operators; they are:

1. Assignment Operator

To assign a value to a variable or a constant, we use the assignment operator. In apex programming, we use “=” as an assignment operator.

Example: int a=10;

In the above statement, we use the “=” operator to assign ten-value to the integer variable “a”.

2. Arithmetic Operators

To perform an arithmetic operation on the given input values, we use arithmetic operators. Arithmetic operations include Addition, Subtraction, Multiplication, Division. We will use the following operators for Arithmetic operations:

  • We will use the “+” operator for the Addition operation.
  • We will use the “-” operator for Subtraction operation.
  • We will use the “*” operator for the Multiplication operation.
  • We will use the “/” operator for Division operation.

3. Unary Increment or Decrement

To increase the value of a variable, we use the increment operator, and the decrement operator is used to decrease the value. 

The increment operator is represented as follows:

  • ++x - Pre-Increment
  • X++ - Post-Increment

The Decrement operator is represented as follows:

  • --x - Pre-Decrement
  • X-- - Post-Decrement

4. Relational Operators

The relational operators are used to tell the relationship between two variables. Various relational operators supported by apex programming are as follows.

  • Greater than(“>”): Greater than operator tells which variable is greater than the other variable. Example: x>y
  • Lesser than(“<”): Lesser than operator tells which variable is less than the other variable. Example: x
  • Greater than or equal to(>/=): This operator is used to tell whether the variable is greater or equal to the other variable.
  • Lesser than or equal to(
  • Not equal (!=): This operator is used to establish a not equal relationship between the two variables.

5. Arrays

In Apex Programming both Arrays and Lists are the same, but the declaration of Arrays is different from Lists. Array declaration is shown as follows

Index of 0= CaCO3.

Index of 1= H2SO4 .

Index of 2=HCl

Access Specifiers in Apex Programming

Access specifier tells us who has the authentication to use a particular data member. Different Access Specifiers supported by Apex Programming are

1. Public

This access specifier gives access to classes, methods which are used by apex inside a namespace.

2. Private

This access specifier provides access to methods, classes, which are to be used locally or inside the part of a code. The data members who do not have any particular access specifier will take this access specifier as their default access specifier.

3. Protected

This access specifier provides access to variables, methods which are to be used by an inner class present in another apex class.

4. Global

This access specifier provides access to variables, methods which can be used inside the apex namespace and outside the namespace.

Sample Apex Program

Apex program to find the largest element in an array

Integer X [] = new Integer[] {150,100, 50};
for(Integer j=0; j<X.Size()-1; j++) {
if(X[j]>X[j+1]) {
Integer temp=X[j];
X[j]=X[j+1];
X[j+1]=temp;
}
}
System.debug(‘The Largest element in array is -’ + a[ a.size()-1]);

Conclusion

Apex Programming language is written by the salesforce.com.It enables the developers to implement the transaction and flow control statements over the Force.com platform. It allows the developers to insert the business logic to the system events. It has all the features that are present in programming languages like C, Java, etc. Salesforce developers can use this programming language to develop user-friendly applications. 

In the next topics, we will discuss in detail about “Controlling the program flow in Salesforce”. Keep following us for more info on Salesforce Development / Programming.

Are you looking to get trained on Salesforce, we have the right course designed according to your needs. Our expert trainers help you gain the essential knowledge required for the latest industry needs. Join our Salesforce Certification Training program from your nearest city.

Salesforce Training Chennai, Salesforce Training Dallas, Salesforce Training Bangalore, Salesforce Training Hyderabad, Salesforce Training Mumbai, Salesforce Training Delhi, Salesforce Training Noida, Salesforce Training New York, Salesforce Training Chicago, Salesforce Training Kolkata, Salesforce Training Gurgaon, Salesforce Training Pune.

These courses are equipped with Live Instructor-Led Training, Industry Use cases, and hands-on live projects. Additionally, you get access to Free Mock Interviews, Job and Certification Assistance by Certified Salesforce Trainers.

Mindmajix offers different Salesforce certification training according to your desire with hands-on experience on Salesforce concepts