Getting Started with Apex

Introduction

Apex is strongly typed, object oriented programming language. It is a proprietary language developed by salesforce. It allows us to write code on force.com platform and developers to execute flow and transaction control statement on salesforce platform. Syntax looks like Java.

Features

  • Database Integration: Tightly coupled database allows us to use inline SOQL and SOSL queries which returns list of sObject records. DML calls are allowed in apex code. It supports triggers, which are piece of code execute before or after DML calls.
  • Web service Integration: It enables creation of web services, allowing integration with external system and development of REST and SOAP API.
  • Integration with Lightning Components: Apex allows us to write server side logic for modern UI frameworks.
  • Multitenant: Multitenancy is a model in which multiple organizations share common infrastructure and codebase, but their data and configuration are isolated and secured. Apex Runtime Engine guard against runaway codes. Governor limits ensures efficient use of resources and prevent code from monopolizing the resources.
  • Own Testing Framework: Salesforce provides robust testing framework for apex, allowing developers to write unit tests to ensure reliability and stability of code. Test results indicate how much code is covered and which part of code could be more efficient. At least 75% code coverage is mandatory for deployment.
  • Security Controls : Security Model of Salesforce like field level security, object and user permissions etc. ensure secure environment, data isolation and permissions of users.
  • Community and Ecosystem : Apex has a thriving community of developers, and Salesforce provides extensive documentation, forums, and resources for learning and troubleshooting.

Unsupported Features of Apex:

  • Cannot show element in UI except error messages.
  • Cannot change standard Salesforce functionality.
  • Cannot use to create temporary file.
  • Cannot create multiple threads.

When should I use Apex Code?

  • Complex Business Logic that aren’t supported by Flow Builder.
  • Bulk Data Processing
  • Custom RESTful service. Apex provide programmatic interface for external system to interact with salesforce data.
  • Dynamic record creation and updates. If requirement involves intricate conditions or need to perform DML operation on basis of external system data.
  • Custom UI. If need to develop dynamic and responsive UI.
  • Perform complex validation over multiple objects.
  • Create custom transactional logic (logic that occurs over the entire transaction, not just with a single record or object).

It’s important to note that while Apex code provides a high degree of flexibility, it comes with the responsibility of coding, testing, and maintaining the solution. Declarative tools like flows and process builders are often preferred for their ease of use, rapid development, and lower maintenance overhead. It’s a good practice to leverage declarative tools whenever possible.

Difference between Apex and Java

ParametersJavaApex
PurposeIt is a general purpose programming language. It’s usage are web development, mobile application and standalone application.Specifically designed for salesforce platform. It’s usage are automating business processes and developing custom complex logic.
Database IntegrationJava needs to use JDBC or other database access mechanism to interact with databases.Apex has built-in support for SOQL and SOSL to query and manipulate data directly within the Salesforce database.
TriggersNot available. Typically handle events through callbacks and event listeners.Apex supports triggers, which are pieces of code that execute before or after records are inserted, updated, deleted, or undeleted in Salesforce.
DevelopmentVariety of IDEs like Eclipse, IntelliJ IDEA, or NetBeansSalesforce provides its own web-based development environment called the Salesforce Developer Console, and developers can also use tools like Visual Studio Code with Salesforce extensions for Apex development.
Governor LimitsIn traditional Java applications, there are no inherent governor limits. The application’s performance is limited by the resources available on the server.Salesforce enforces governor limits to prevent code from monopolizing resources and negatively impacting the performance of the shared multitenant platform.
Security ModelJava applications need to implement their own security measures, and the security model is not inherently tied to a specific platform.Apex leverages the security model of the Salesforce platform, including features like field-level security, object permissions, and user roles.
Deployment ModelsJava applications can be deployed on various servers or cloud platforms, and the deployment process depends on the specific hosting environment.Apex code is deployed directly to the Salesforce platform, and the deployment process is managed through Salesforce tools like Change Sets, Salesforce CLI, or Metadata API.
Difference between Java and Apex

While Apex and Java share similarities in terms of syntax and object-oriented concepts, the differences in purpose, integration with the platform, and specific features make Apex more tailored for developing applications on the Salesforce ecosystem.

You may also like...

Leave a Reply

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