- Igor Codes
- Posts
- Variable question
Variable question
Everyone wants to jump and create a trigger that makes an API call to the ERP system while firing a batch and parsing the Visualforce page into a PDF.

And then – oh wait, what exactly is a variable in Apex?
Let’s have a look at a simple example:
String name = 'Alex';
This is how it looks inside the memory

The variable is just a pointer to the actual value. It contains only two pieces of information:
Variable name
Address of the value

Let’s look at another example. Nothing too crazy, just a new variable!
String name = 'Alex';
String anotherName = 'John';

Now, let’s do something mind-blowing, let’s re-assign one variable to another:
name = anotherName;
System.debug(name); // ???
What do you think will be printed out? That’s right, it will be “John”!
We assigned the value from “anotherName” to “name”, so they both now point to the same information.

What happens to the “Alex” value in memory? It will be deleted by the Apex engine, as it’s not used anymore.

This week’s newsletter is quite technical. If you want more coding stuff in the newsletter reply “coding”, if you want more career-related - reply “career”.
That will help me understand what to write, any feedback appreciated 🙂