opencodez

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.

public interface Order{

Double TotalBill();

Double getDiscount();

}

Let’s define one class implementing this interface.

public class Customer implements Order {

	public double Total_Bill = 0.0;
	static final double discount = 0.7;

	public double TotalBill() {
		return Total_Bill;
	}

	public double getDiscount() {
		return discount;
	}
}

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:

Order my_order = new Customer();

The data in apex is divided into the following types:

Miscellaneous Syntax

Following annotation are used with methods:

@future: x 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.

public class triggerInvokeExample {

	public static void yourMethod(){

		// method definition here

	}
}

Trigger definition:

Trigger testTrigger on Order{before insert) {
	triggerInvokeExample.yourMethod();
}

Difference between Controller x 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:

Introduction of test class x 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.

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