Skip to content

What the heck is this whole Apex stuff?

In short nerdy words, Apex is a strongly-typed, object-oriented programming language. It is a proprietary language of the Lightning Platform that is saved and run in the multi-tenant cloud platform.

I heard this is kind-of-Java

Syntactically, yes, Apex is similar to Java. If you can program in Java, you are really close to being an Apex developer! But no, this is not Java. It is compiled like Java, it has a Java Virtual Machine in the background – somewhere – but it’s not a full-fledged VM, only the part of it.

If you are really interested in details – well, they are internal only to Salesforce, but you may dig out some nice details in this patent: Patent US20110264861: Methods and systems for utilizing bytecode in an on-demand service environment including providing multi-tenant runtime environments and systems.

I heard that in Apex I can’t do X, Y, and Z – why should I even waste my time reading about some strange language!

You may treat it on a high level as a simplified version of Java. 

But hey, do you really need ArrayList, LinkedList, Stack, Vector, TreeSet, LinkedHashSet, HashSet, HashMap, TreeMap, and many more just to store some records

In Apex there is List, Set, and Map. Easy to pick, easy to use!

This is a language to DO the work. And yes, you can do Dependency Injections if you want.

According to Salesforce: Apex is exclusively for building business applications to manage data and processes within the larger context of the Apex Lightning Platform framework. But within the scope of business applications, Apex Code provides a uniquely powerful and productive approach to creating functionality and logic, allowing developers to focus just on the elements specific to their application while leaving the rest of the “plumbing” to the platform’s framework

Pretty strong claim! Isn’t it just some marketing? NO!

But please, if you really want to spend 95% of your time configuring servers, databases, microservices, interfaces, gateways, load balancers, backup, and deployment.. oh and yes, security and redundancy – pick another language and another platform.

Apex is:

  • Integrated with the database – you can do inline queries and loops, e.g. fetch Id and Name from Contact Table (1) that got mailing address in Poland, but please join Account Table (2) and pick only the Contacts under Accounts that got “soft” in the name. Iterate over the list, introduce changes (3) and then just push the update back into the database (4). How much work do you need to do in another language? Check this!
  • Versioned, you can have multiple classes calling each other and all those classes can run in their own version – yes, this 10 years old Apex can co-work with those shiny brand new features that you have just built! And you have 3 big releases per year. Each release = new features.
  • Easy to use – the syntax is similar to Java, Apex methods are well documented and there is a very strong community around it.
  • Rigorous – Apex is strongly typed and compiled. It fails quickly at compile time if any references are invalid. It stores all custom field, object, and class dependencies in metadata to ensure that they are not deleted while required by active Apex code. So – nobody will delete a column in the database if you are using it!
  • Transactional – All DML operations in a transaction either complete successfully or, if an error occurs in one operation, the entire transaction is rolled back and no data is committed to the database – automatically!
  • Packable – you can pack your code and sell it on AppExchange! Or just grab some ready components and re-use them in your instance.

If I really have to, where can I use it?

In one word – the whole backend! And what is the backend for Salesforce?

Anonymous blocks:

You can use anonymous blocks, compiled and executed on the fly, not stored anywhere.

Want to do a quick data fix? No problem! Send some emails? Go ahead!

Triggers:

Yes, the same language! Apex triggers enable you to perform custom actions before or after changes to Salesforce records, such as insertions, updates, or deletions. 

Controllers in MVC patterns:

Yes, Again. Same language. Apex.

REST Web Services and SOAP Web Services:

Why not? Expose the data you want, on the rules you want with OAuth2.0 or fully custom authentication. In a few lines of code! Here we got an “Account” endpoint where you pass Id via URI and get some extra details about it.

Email processing:

You can expose an email address in Salesforce and do any custom email processing. E.g.: If you receive an email, and you do not have a Contact connected with that email, you can create one.

Event-driven development:

Yes! Yes! Yes! You got an enterprise-level event bus that you can just use in your code! Did anyone say “Kafka”?

Kubernetes-based serverless environment

Salesforce Evergreen brings in serverless functions based on fully-managed Kubernetes, support for open programming languages, and commonly used high-performance data stores. Evergreen supports technologies and architectural patterns like:

  • Functions-as-a-Service (Node.js, Java, and Apex)
  • Microservices
  • Managed data stores (Postgres, Apache Kafka, and Redis)

Yes, all those nice, shiny things on that ugly Salesforce platform! Maybe not so bad in the end?

I heard that developers hate it!

Apex enforces good programming practices by 2 core design features:

  • test-enforced deployment 
  • governor limits

So yes, if you do not like testing and writing optimal code, you will not like it, sorry! 

Testing!

It’s easy to test, Apex got built-in support for unit test creation and execution, you exactly know which line is covered and which needs some extra attention. You can mock external services so also REST API and SOAP API integrations can be well-covered.

And – you just cannot push the code to the Production if at least 75% of the code is not unit tested! HATE!!!

Governance limits!

Do you like to write database queries in for loop? You will be punished!

Do you like to query the whole database table if you need only 2 fields in 4 records out of 10 million-record table with 500 columns? You will be punished!

Do you like to use O(n^4) algorithms? Yes, you will be punished!

But hey, you can simply start writing good code! Because Apex runs in a multitenant environment, the Apex runtime engine strictly enforces limits so that runaway Apex code or processes don’t monopolize shared resources. If some Apex code exceeds the limit, the associated governor issues a runtime exception that cannot be handled.

Are there any job positions there for this whole Apex?

Well, I know quite a lot of people that have been programming in Java and went into the Salesforce world. I do not remember any leaving Salesforce for Java. Hmm… 

Money? Interesting job? Various assignments? Different applications? No idea what the reason is! 

Usually, we say that we have someone called a Salesforce Developer. Such a person is working mainly with backend – yes, Apex. But, most of the developers are more like “ninjas” – we’ve got a lot of frontend in Salesforce in form of Lightning Web Components (modern Web Component framework), Lightning Components (a bit older, Aura framework-based) or Visualforce Pages (MVC pattern). When you work with Salesforce, you broaden your knowledge not only about Apex (a strong backend object-oriented programming language) but also about JavaScript, HTML5, CSS3, and modern web technologies. 

More than 150 000 companies, across every industry, are using Salesforce. Heard about Adidas, AWS, T-Mobile, Philips, Toyota, ABB, Spotify, EA, Activision, GE, KLM, Nielsen, PWC, Pandora, Shazam, Unilever – all of them are quite niche companies, aren’t they? 

OK, so can I learn it somewhere without paying a lot of money?

Salesforce’s got a developer edition that is free to use! 

There is also a Trailhead platform https://trailhead.salesforce.com/ where you can learn from the very beginner to the architect level for free! This learning platform is heavily gamified with real-life topics, chunked into easily digestible 15-20 min parts.

And just google it – there is a lot of high-quality materials available at your fingertips!

So – are you ready to blaze your trail? 

Welcome to the Salesforce world!

Would you like to learn more about Apex or being a Salesforce Developer at Cloudity? Contact us!

We also encourage you to follow us on LinkedIn.

Article by Jakub Kalke