3.5 Public and private modifiers

The concept

In Apex programming language, there are three access modifiers: global, public and private. Global means it can be accessed inside and outside the current package. It is generally used when we build a library or web service. We can ignore it for now if you find it hard to understand. Public means it can be accessed inside the package, but pretty much everywhere in your current org. Private means it can only be accessed within the current class.

• • •

2.6 Variable naming conventions

The concept

In our previous posts, we mentioned that you can pretty much name your variable anything you want. But it doesn’t mean you should give them just random names. For Apex compiler, it really doesn’t make any difference. But remember, our programme is written for human to read, not for compilers.

• • •

3.4 Pass by value and pass by reference

The concept

Today, we are going to learn a very important concept of programming. Pass by value and pass by reference. In Apex, all the primitive type variables are pass by value and all the object type variables are pass by reference.

• • •

3.3 Use methods that takes parameters

The concept

In our previous post ,  we mentioned that variables can only store values. It doesn’t remember the formula. Remembering formula can be achieved via functions. Now let’s do it. We create a new class in our developer console called Commodity.

• • •

3.2 Use methods

The concept

Following our previous post , a dog not only has some attributes like name and gender, it can also do some certain behaviours. Like, they can bark, walk, they can greet you. When implemented in programming, such behaviours are defined as methods or functions. Method and function in apex can be used interchangeably. Here is the code, following our previous post:

• • •

3.1 Define a custom object using class

In this chapter, we are going to cover the very basics of custom class, object and method. Object-Oriented programming is a complicated concept and we will cover it in more details later. In this chapter, I will show you about how to create and use a custom class, and how to utilize methods to write dry code.

• • •

2.4 Variables only store data

The concept

A variable is a container of a small piece of information. And it only remembers the value of that information. It doesn’t know know how is that value generated or where it is coming from. This concept might seem easy, but it is worth taking some time really understanding it. Here is a sample code.

• • •

2.2 Variable types and conversions

The concept

In our last post, we mentioned that Apex is a strong typed language, which means each variable must have a type and that cannot be changed. In this post, I will show you a number of frequently used variable types in Apex and a few basic operations. Here comes the code:

• • •