Simplisfdc.com
Simplisfdc.com

Basics of Apex in Salesforce for Beginer

What is Apex in Salesforce?

Apex in Salesforce is an on-demand, object-oriented programming language.

It is used to write Apex classes or triggers to enhance force.com platform functionalities.

Apex in Salesforce is similar to Java programming language and it is easy to learn using Salesforce’s official learning platform trailhead.

 

Introduction to Apex

Object-oriented

Object-oriented Objects are discrete collections of code (data and associated operations) that are modeled after physical objects.

on-demand

Available on-demand functionality that you require When you need it, it’s in the cloud.
incorporated automatically into other Force.com platform features

 

Java vs. Apex

 

Introduction to Apex -code

Similarities

  • Classes, inheritance, polymorphism, and other typical OOP characteristics are present in both.
  • Both feature syntax and notation that are remarkably similar.
  • Both are strongly typed, compiled, and transactional.

Differences

  • Apex operates in a multi-tenant setting and has very strict governor limits and invocation restrictions.
  • The case is irrelevant in Apex.
  • Apex is compiled and executed in the cloud on demand.
  • Instead of being a general-purpose language, Apex is a proprietary language used for particular business logic operations.
  • Before being installed in a live environment, Apex must pass unit testing.

Apex classes and Triggers

One of two options is used to store all Apex codes.
1. Class: An Apex library of instantiable objects that include attributes and methods.

2. Triggers: An Apex code runs before or after a certain data manipulation language (DML) event on a particular Salesforce object.

trigger TriggerName on ObjectName (trigger_events)

{

code_block

}

where trigger events can be a list of one or more of the events listed below, separated by commas:

  • before insert
  • before update
  • before delete
  • after insert
  • after update
  • after delete
  • after undelete

 

Introduction to Apex

 

How does Apex work?

Using the Lightning Platform, Apex is on-demand. End users initiate the execution of the Apex code through the user interface, which developers build and save to the platform.
On the Lightning Platform, Apex is built, saved, and executed. The Lightning Platform is used exclusively for compiling, running, and storing Apex.
When a programmer creates and saves Apex code to the platform, the platform application server first transforms the code

 

Introduction to Apex

into a set of abstract instructions that the Apex runtime interpreter can understand. Then, the instructions are saved as metadata.

The platform application server pulls the built instructions from the metadata and transmits them through the runtime interpreter before providing the output when an end user initiates the execution of Apex, possibly by clicking a button or browsing a Visualforce page. The end user doesn’t notice any delays in response time compared to regular platform requests.

Various ways apex is invoked

You can execute Apex code asynchronously, via triggers, or as SOAP or REST web services.

Anonymous Blocks

Apex code that can be compiled and executed but isn’t recorded in the metadata is known as an anonymous block.
Triggers are a method of launching Apex. You can execute custom actions before or following changes to Salesforce records, such as insertions, updates, or deletions, thanks to apex triggers.

Apex Asynchronous

Apex provides several options for asynchronously running your Apex code. Choose the asynchronous Apex functionality that most closely matches your requirements.

Apex Methods Made Available as SOAP Web Services

So that outside apps can access your code and your application, you can expose your Apex methods as SOAP web services.

 

Introduction to APex

Apex Classes Are Made Available as REST Web Services

You can make your Apex classes and methods available so that other applications can use the REST architecture to access your code and your application.

Email service Apex

Email services can be used to process the body, headers, and attachments of incoming emails. For instance, you may develop an email service that generates contact records from message contact information.

Making use of the InboundEmail Object

Salesforce creates a unique InboundEmail object for each email the Apex email service domain receives, which comprises the email’s contents and attachments. Apex classes that implement the Messaging can be used. An inbound email message is handled by the InboundEmailHandler interface. You can get the contents, headers, and attachments of incoming email messages as well as carry out several other operations using the handle inbound email method in that class.

Class Visualforce

Using customized Visualforce controllers and controller extensions, Apex may be used to offer custom logic for Visualforce pages, allowing developers the opportunity to apply business logic to Salesforce system events like button clicks and related record updates.

Using JavaScript Remote

To call methods in Apex controllers using JavaScript, use Visualforce remoting. Build dynamic, complicated pages that aren’t achievable using the default Visualforce AJAX components.

AJAX’s Apex

The Apex toolkit has built-in support for calling Apex using public web service methods or anonymous blocks.

Click here to start learning Apex using the trailhead

 

You May Also like:

Check Also

10 Tips and Tricks for Getting Things Done on Slack

10 Tips and Tricks for Getting Things Done on Slack

10 Tips and Tricks for Getting Things Done on Slack About 20 million people across …

Leave a Reply

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