Salesforce Tutorial# 16: Learning Salesforce Apex and Deployment Tools

Apex is the backbone of Salesforce development. In this article, we will see a few points that will help you in Learning Salesforce Apex.

Introduction of Salesforce Apex Classes:

Apex is more similar to Java and C# programming language with a set of features like constants, classes, class variables, interfaces, and annotations.

Classes and Interfaces

Following snapshot of code explains the sample example of an interface, remember Apex is not case sensitive.

Let’s define one class implementing this interface.

Similar to Java implement keyword is used for interface implementation. The meaning static, final is similar to java programming language. The class instance can be created as follows:

The data in apex is divided into the following types:

  • Primitive data types like Integer, double, long, String, Blob – for storing binary data, Boolean, Date, Time and Date-time, Decimal – for representing arbitrary procession numbers, including currency, ID – the Force.com database record identifier type.
  • sObject types that represent persistent objects
  • Collections (Sets, Lists, Maps) and enumerations
  • User and system-defined Apex classes
  • Statements (While, For loops, if) and Expression
  • Property to declare a variable with its getter and setter
  • Apart from this Apex supports Exception handling with the same try, catch and finally mechanism.

Miscellaneous Syntax

Following annotation are used with methods:

@future: – this is used to represent asynchronous executions of methods

@isTest:- This is class annotation and represents that all the methods are a test

Invoke a class or its method via Triggers

This is similar to call a native method from other programming languages. The method is defined in the Apex class can be a static or non-static method. We will create an instance of the class inside trigger to call its method or static methods that can be invoked by class name only.

Trigger definition:

Difference between Controller & Extension

A user define controller is known as a custom controller, this is an Apex class having a logic that doesn’t enforce the permissions and take care of field-level security of the current user.

Extensions are used to extend the functionality of the controller. Following are a few scenarios to use controller extensions:

  • You want to make flexible the built-in functionality of a standard controller but already override one or more actions like edit, view, save, or delete.
  • If new actions need to be added
  • Build a Visualforce page that secures user permissions. Let’s consider the scenario that a controller extension class executes in system mode, and controller extension extends a standard controller, still, the logic from the standard controller does not execute in system mode but it executes in user mode and the permissions, level of security, sharing rules will be applied as per current user.

Introduction of test class & methods to cover Apex

Apex Code has a facility for the creation and execution of unit tests for robust and error-free code development. These unit tests are composed of test methods and classes which execute the verification for a piece of code working properly.

Deployment Tools:

Salesforce support following deployment tool to make data migration more comfortable. A tool like Change Set is used to migrate data between sandbox and production.

Force.com IDE (Eclipse Plugin)

The Force.com IDE is based on Eclipse platform and supports many API and integrated with the development environment letting you code, compile, and deploy your application.

Force.com Migration Tool (Ant-Based)

The Ant Migration Tool is a command-line utility developed in Java for moving metadata between a local directory and a Salesforce. This tool can be used in the following scenarios.

  • When a project needs a lot of setup changes and it’s a time-consuming activity to make these changes using the web interface, then we need a migration tool
  • When your product has multistage release processes. The normal development process requires iterative building, testing, and staging before releasing a product.
  • The migration tool plays an important role when there is repetitive deployment using the same parameters
  • Migrating from stage to production is a need to done.
  • When we need to schedule batch requirements.

Summary

This article gives you head start in Learning Apex. It has briefly covered the deployment tools offered by Salesforce. If you wish to refer previous articles then do check our other articles in the series.

Tutorial Index

  1. Introduction to Cloud Computing (Salesforce.com and Force.com)
  2. Overview of Database Concepts (Salesforce.com)
  3. Introduction to Force.com
  4. Building Salesforce Custom App and Objects
  5. Object Relationships and Formula Field in Salesforce
  6. Salesforce Security Model and Overview
  7. Automation in Salesforce
  8. Approval Process in Salesforce
  9. Introduction to SOQL and SOSL
  10. Introduction to Apex
  11. Salesforce Data Management
  12. Visualforce MVC Architecture on Cloud
  13. Salesforce Reports and Dashboards
  14. Building a Visualforce (Custom) Page for the Salesforce App
  15. Salesforce Sandbox and Overview of Force.com capabilities
  16. Learning Apex and Deployment Tools

Add a Comment

Your email address will not be published. Required fields are marked *