Deprecated: trim(): Passing null to parameter #1 ($string) of type string is deprecated in /home1/oijoiv2f/public_html/wp-content/themes/entaro/template-posts/single/inner.php on line 23

Apex Programming for Beginners

Apex Programming for Beginners

Introduction to Apex Class and Trigger

What is Apex Programming and why is it required for customizing Salesforce?

Apex is an object oriented Programming language, it is stored, compiled and run on force.com platform and is, therefore, on-demand programming language.

Apex’s syntax is similar to Java, they behave similar to a stored procedure, and the logic written in Apex can be linked to the record save procedure. Salesforce’s apex provides features for unit test creation and execution.

What are the capabilities of Apex?

Apex help in programmatic access to the exposed Salesforce.com feature. The list of these features is mentioned below.

Actions, Approval process, Authentication, chatter, communities, email, metadata, Salesforce knowledge, Salesforce connect, territory management, visual workflow etc.

What are Apex transactions and Governor limit?

Salesforce has made its foundation based on multi-tenant architecture, to ensure the resources are used efficiently, Salesforce introduced the governor execution limit. Following terms are used together when it comes to talk about Governor limits.

Mostly Governor limits are applicable per Apex Transactions basis, but some are on rolling 24 hours basis. Apex transaction is the execution of a set of operation as one unit, boundary of the transaction can be a trigger, anonymous code or a web service etc.

Execution Governors and Limits- since Salesforce is in a multitenant environment,  its servers ensures that a single apex code does not monopolize all the resource and keeps a check on all the execution and these checks are known as governor limits.

Running Apex within Governor Execution Limits- sometimes there arises a need or requirement which wants us to execute code which will breach the governor limit. In those circumstances, to adhere to these limits certain design patterns are used, i.e. bulk calls and relationship queries.

Getting started with Coding in Apex

Before we proceed to deep dive into the code we need to know certain fundamentals of Apex.

As we mentioned earlier, the syntax of Apex is similar to java, but there are other fundamentals as well which are quite similar, below are the features similar to Java.

Data Types and Variables

Control Flow Statements

Classes, Objects, and Interfaces

Working with Data in Apex

Data Types and variables

All variable in apex have a data type, it is basically an alias for a memory location allocated to hold a value. For eg. sObject, integer, enum etc.

Then Salesforce has primitive data type, integer string, double etc. It also has collections namely list, set and Map.

Control Flow Statements

To control the flow of statements, apex provides if-else and loops.

Conditional (If-Else) Statements

Loops

Loops

Apex is presently supporting 5 types of loops, namely: while loop, do while loop, for loop, for-each loop

For loop with SOQL as an argument.

Objects interface and classes

Similar to Java, Apex is also based on the concept of Classes, interface, and objects. So what is the difference between a Java class and Apex Class, main differences are mentioned below:

  1. Classes and methods are final by default.
  2. Default access modifier is private, i.e. specifying no access modifier and declaring privately is synonymous in Apex.
  3. An interface is always global, no other access modifiers are allowed.
  4. Inner class and interface are allowed only one level deep, inner class behaves like static without specifying it as static.

How to create a class?

Salesforce has provided us with the  Apex and Visualforce editor in the UI. There are many ways to reach the editor.

Kindly note that Apex class and triggers can only be created in either sandbox or developer edition, but Visualforce is allowed to be created at the production environment.

Apex Class editor has a help text inbuilt, this helps in auto completion of the syntax, which save a lot of time.

Now with all the Bookish knowledge which is available on the internet, we should now proceed to write some code.

Next : Working with Data

Sumit Datta

Sumit Datta

I am a 5x Certified Salesforce developer with overall 7 years of IT experience and 5 years of Implementation experience in Salesforce. I am here to share my knowledge and help Beginners in Salesforce to understand the concepts of Apex, Visualforce, Salesforce Lightning and Salesforce Configuration.

1 Comment

  1. […] They are similar to SOAP API, therefore generic sObject abstract type can be used to represent any object. DML works on both generic sObjects and regular sObjects. Ex: Account acc = new Account(); Object__c custObj = new Object__c (); Casting of sObjects : sObject s = new Account(); Account a = (Account)s; —– Allowed Contact c = (Contact)s; —– Not Allowed. Apex Programming for Beginners | SalesforceNextGen. […]

Leave a Comment

Your email address will not be published.