Salesforce Apex is like the first programming language. Pros and cons

Apex became my first programming language. It is a Java-like language that automates backend logic into platform applications Salesforce.com

This is not to say that I was not familiar with OOP or other languages ​​before. My acquaintance was limited to theoretical knowledge, half-completed courses in Codecademy or laboratory work at the institute. Naturally, all the subtleties of technology, the syntax of the language, its capabilities and limitations quickly disappeared from memory, since I did not find any practical application for these skills.

In 2019, I joined Accenture as a Salesforce CRM support and refinement specialist. The range of tasks was not clearly delineated at first, so I began to study both administration and development tools in Salesforce.

Now my experience in Apex development is about a year, I became a certified Salesforce developer. I can summarize the first results.

It will be useful for:

  • beginners in programming

  • Salesforce admins looking to master development

  • experienced developers who want to learn about development on the Salesforce platform

Below I will briefly summarize all the pros and cons of Apex, in terms of choosing it as a language for learning. Then I’ll take a closer look at each point.

Pros of Apex:

  1. Apex teaches you how to write optimal, resource-efficient code

  2. Apex teaches unit testing and test-driven development

  3. Apex has consistent and up-to-date documentation collected from the Salesforce portal

  4. Apex has out-of-the-box access to the database (no need to write connectors)

  5. Apex is 90% Java. You can easily understand Java code after developing with Apex

  6. Salesforce supplies its own online IDE Developer Console that allows a beginner to quickly start programming without diving into the world of custom IDEs

  7. Apex can be mastered in Trailhead sandboxes, without installing and configuring additional software.

  8. Trailhead teaches Apex programming from scratch. Trailhead modules teach you OOP concepts and Apex syntax in the language of mere mortals (unfortunately only in English)

Cons of Apex:

  1. Few materials in Russian (almost none)

  2. Small Russian-speaking community

  3. Applicable only for products on the Salesforce platform

Apex teaches you how to write optimal, resource-efficient code

Resource efficient code in Apex is not a whim or a recommendation, but almost a necessary condition. Because Salesforce is a cloud-based platform, the software resources for each platform client are licensed. In other words, the resources you have at your disposal as a developer are limited. Salesforce limits

Code, the execution of which violates the limits, will lead to a system error and a rollback of the transaction. For this reason, Salesforce has recommendationwhich you need to adhere to in order to write optimal code.

I consider this point a plus of Apex, because from the very beginning you get used to writing optimal code that economically manages cloud resources. This forms a useful way of thinking for the developer.

Apex teaches unit testing and test-driven development

Code coverage by unit tests by 75% is a prerequisite for porting this code to the PROD environment. Therefore, you learn from the very beginning to create test classes. It’s a useful skill to change the mental angle from which you look at your code so that you can write a test.

Salesforce takes this a step further and advocates starting with writing unit tests when developing. This helps you better understand all the custom scenarios that your future code must handle. Therefore, Apex, as the first programming language, leaves you with no choice: you immediately learn the best practices and a conscious approach to the development process.

Sample class and test class in Apex

Class:

public class TVRemoteControl { 

    // Volume to be modified 

    Integer volume; 

    // Constant for maximum volume value 

    static final Integer MAX_VOLUME = 50;     

     

    // Constructor 

    public TVRemoteControl(Integer v) { 

        // Set initial value for volume 

        volume = v; 

    } 

         

    public Integer increaseVolume(Integer amount) { 

        volume += amount; 

        if (volume > MAX_VOLUME) { 

            volume = MAX_VOLUME; 

        }  

        return volume; 

    } 

     

    public Integer decreaseVolume(Integer amount) { 

        volume -= amount; 

        if (volume < 0) { 

            volume = 0; 

        }   

        return volume; 

    }     

     

    public static String getMenuOptions() { 

        return 'AUDIO SETTINGS - VIDEO SETTINGS'; 

    } 

        

} 

Test class:

@isTest 

class TVRemoteControlTest { 

    @isTest static void testVolumeIncrease() { 

        TVRemoteControl rc = new TVRemoteControl(10); 

        Integer newVolume = rc.increaseVolume(15); 

        System.assertEquals(25, newVolume); 

    } 

     

    @isTest static void testVolumeDecrease() { 

        TVRemoteControl rc = new TVRemoteControl(20); 

        Integer newVolume = rc.decreaseVolume(15); 

        System.assertEquals(5, newVolume);         

    }  

         

    @isTest static void testVolumeIncreaseOverMax() { 

        TVRemoteControl rc = new TVRemoteControl(10); 

        Integer newVolume = rc.increaseVolume(100); 

        System.assertEquals(50, newVolume);         

    } 

     

    @isTest static void testVolumeDecreaseUnderMin() { 

        TVRemoteControl rc = new TVRemoteControl(10); 

        Integer newVolume = rc.decreaseVolume(100); 

        System.assertEquals(0, newVolume);         

    } 

     

    @isTest static void testGetMenuOptions() { 

        // Static method call. No need to create a class instance. 

        String menu = TVRemoteControl.getMenuOptions(); 

        System.assertNotEquals(null, menu); 

        System.assertNotEquals('', menu); 

    } 

} 

Apex has consistent and updated documentation collected from the Salesforce portal

Salesforce is developing Apex as the main language for development on its proprietary platform, so all updates and all documentation are contained on a single official portal Apex Developer Guide

It contains all the system classes and methods, and describes in detail their purpose and application. You can find a definite answer to most of the questions. And there are always a lot of questions during training.

Apex has out-of-the-box access to the database

A big plus for a novice Apex developer is the ease of accessing the database from code. The database can be accessed from anywhere in the code, no additional settings or connections are required.

Here are some examples of accessing the database from code:

Account A = new Account(Name="xxx");
insert A;
Account B;

// A simple bind
B = [SELECT Id FROM Account WHERE Id = :A.Id];

// A bind with arithmetic
B = [SELECT Id FROM Account 
     WHERE Name = :('x' + 'xx')];

String s="XXX";

// A bind with expressions
B = [SELECT Id FROM Account 
     WHERE Name = :'XXXX'.substring(0,3)];

// A bind with an expression that is itself a query result
B = [SELECT Id FROM Account
     WHERE Name = :[SELECT Name FROM Account
                    WHERE Id = :A.Id].Name];

Contact C = new Contact(LastName="xxx", AccountId=A.Id);
insert new Contact[]{C, new Contact(LastName="yyy", 
                                    accountId=A.id)};

// Binds in both the parent and aggregate queries
B = [SELECT Id, (SELECT Id FROM Contacts
                 WHERE Id = :C.Id)
     FROM Account
     WHERE Id = :A.Id];

// One contact returned
Contact D = B.Contacts;

// A limit bind
Integer i = 1;
B = [SELECT Id FROM Account LIMIT :i];

// An OFFSET bind
Integer offsetVal = 10;
List<Account> offsetList = [SELECT Id FROM Account OFFSET :offsetVal];

// An IN-bind with an Id list. Note that a list of sObjects
// can also be used--the Ids of the objects are used for 
// the bind
Contact[] cc = [SELECT Id FROM Contact LIMIT 2];
Task[] tt = [SELECT Id FROM Task WHERE WhoId IN :cc];

// An IN-bind with a String list
String[] ss = new String[]{'a', 'b'};
Account[] aa = [SELECT Id FROM Account 
                WHERE AccountNumber IN :ss];

Apex is 90% Java. You can easily understand Java code after developing with Apex

Salesforce built Apex using Java syntax. There are small exceptions due to the specifics of Salesforce. All differences are collected on this page

But, if you look at the methods of working with primitives and collections, they work similarly to Java.

Compare, for example, methods of working with String to Apex and String in Java

It turns out that while learning Apex, you also learn Java a lot. This rule works and vice versa.

If you decide to move to Java Developers, you don’t have to start from scratch. And the helpful thinking paradigms from Apex development will give you a solid foundation for writing resource-efficient Java code.

Salesforce Delivers Its Own Online IDE Developer Console

The Developer Console allows a beginner to quickly start coding without diving into the world of custom IDEs.

I remember how I used to try to learn Python, C # on my own. And you had to start by installing the IDE, configuring it. Understanding how this IDE works is another story. Many folders, many buttons, many menu items, many panels. This was a serious barrier to the beginning developer.

With Apex, nothing like this has happened, since any Salesforce instance contains a built-in IDE called the Developer Console. You don’t need to install anything, just open the Developer Console in your browser and write the code right away. You can run the code right away and test it in a real (or sandboxed) application.

Yes, more experienced Salesforce developers prefer to work in Visual Studio Code or Eclipse, but for beginners, the Developer Console is the way to go.

The Developer Console looks like this:

Apex can be mastered in Trailhead sandboxes, without installing and configuring additional software

Salesforce has developed its own training platform – trailhead.salesforce.com… It is great for the gamification of the learning process and the fact that you can create test environments directly from the practice page:

As part of the training, you can have up to 10 (!) Active sandboxes simultaneously. You can delete sandboxes and create new ones for each next task, or you can work in one sandbox for several tasks at once. Any new sandbox is created with pre-filled data so you can start experimenting right away and not waste time filling in with test data.

Trailhead teaches Apex programming from scratch

Trailhead has a variety of learning modules and trails (sequences of modules). The main plus for a beginner is that for learning programming, you can choose a “path”, which is intended for students with zero experience or only with admin experience. In this case, the training will start from the very basics of OOP, and Apex code will be used as examples.

Examples of training modules for Apex development for administrators
Examples of training modules for Apex development for administrators

All Trailhead modules are written in English. The authors of the modules try to describe concepts as simply as possible, so the language barrier quickly ceases to be felt.

The text is often supplied with funny examples and just jokes. A typical example in the picture below:

There are some downsides to learning Apex. Below I will consider them in more detail.

Few materials in Russian (almost none)

The following official resources have not been translated into Russian:

  1. Trailhead

  2. Apex Developer Guide

This makes learning difficult for children who do not know English.

Small Russian-speaking community

The number of developers from Russia and the CIS is relatively small, so it is difficult to find blogs and discussion of Apex in Russian. For example, here’s what the professional Salesforce communities of VKontakte look like

It should be noted that development on Salesforce is rapidly becoming popular in Belarus. More and more high-quality videos about Salesforce and Apex appear in Russian-speaking Youtube (example). The number of specialists is growing, but there are still more jobs than people.

This disadvantage can be converted into an advantage for you as a specialist in the labor market. The fewer specialists, the more expensive they are.

Applicable only for products on the Salesforce platform

Unlike Java, Python, and other cross-platform languages, Apex can only be used for development on the Salesforce.com platform. Despite the variety of Salesforce products, you are limited to this stack.

Conclusion

Apex is great for teaching programming. Salesforce rules and guidelines teach you OOP best practices from the start that apply to code in any other language.

However, it is better to look towards other languages ​​to start if:

  • You do not plan to develop professionally as a Salesforce specialist;

  • You do not speak English well. This will make it difficult for you to learn any programming language, but Apex in particular.

Similar Posts

Leave a Reply

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