Layer 0: Pouring the Foundation
Welcome to Absenthome: Lessons in Logic and Layers. This series is designed to take you from a Salesforce Admin to a Systems Architect. We aren't just learning to code; we are learning to build systems that are robust enough to run while you are absent.
In Layer 0, we move from the Salesforce UI into the Developer's Studio. We are laying the "concrete" that every future trigger and class will sit upon.
π οΈ Part 1: The Studio Setup (Prerequisites)β
Before we can build, we need the right tools in our workshop.
1. Visual Studio Codeβ
This is your primary workbench. Itβs where you will write, edit, and manage your "blueprints" (code).
- Download: Official VS Code Site
2. Node.jsβ
We use Node.js to power the Salesforce CLI. Think of it as the electricity running through your studio.
- Download: Node.js Official Site
- Check Version: Open your terminal and run
node --version.
3. Salesforce CLIβ
This is the "truck" that carries your code from your computer to the Salesforce cloud.
-
Install via NPM:
npm install @salesforce/cli --global -
Verify Installation: Run
sf --versionto ensure it's installed correctly.
βοΈ Creating & Connecting Your Orgβ
1. Developer Edition Orgβ
You need a safe space to build where you won't break production.
- Sign Up: Free Developer Edition
- Action: Check your email, reset your password, and save your credentials in a secure location.
2. Connecting the Studioβ
- Open VS Code.
- Install the Salesforce Extension Pack (Expanded) from the Extensions view (
Ctrl+Shift+X). - Open the Command Palette (
Ctrl+Shift+P). - Select SFDX: Authorize an Org.
- Follow the browser prompts to log in. Once successful, your studio is officially connected to the cloud.
ποΈ Part 2: Creating Your First Projectβ
Every building needs a project file. In your VS Code terminal, run the following command to generate your workspace:
sf project generate --name YT-Learning
π§± Part 3: The Building Materials (Variables)β
A Variable is just a reserved spot in computer memory. If you can build a custom field in the UI, you can write a variable in Apex.
The Admin-to-Developer Mapβ
| UI Field Type | Apex Data Type | The Architect's Use Case |
|---|---|---|
| Text / Picklist | String | The Name Tag. Used for names or status. |
| Number | Integer | The Scoreboard. Whole counts (1, 2, 3). |
| Checkbox | Boolean | The Light Switch. true (on) or false (off). |
| Currency / Percent | Decimal | The Receipt. Numbers with a . point. |
| Lookup / ID | Id | The Passport. The unique record fingerprint. |
| Date / Time | Date | The Calendar. A specific point in time. |
π¦ Complex Variables (The "Containers")β
1. The sObject (The Apartment)β
In the UI, this is a Single Record (like an Account page). In Apex, itβs a container holding all those fields in memory.
- Example:
Account myAccis like holding the "Edge Communications" record in your hand.
2. The List (The Building)β
In the UI, this is a List View. Itβs a collection of records.
- Why it matters: Just like checking boxes in a List View for a "Mass Update," a List in code lets you process 200+ records at once.
βοΈ Part 4: Building the Engine (Logic)β
π¦ The Decision Layer: Conditionals (if/else)β
This is exactly like the Decision Element in Flow.
if (doorStatus == 'Open') {
System.debug('Turn on the light');
} else {
System.debug('Keep it dark');
}
π The Processing Layer: Loops (for)β
If a variable is a brick, a Loop is the assembly line. It allows us to process entire Lists efficiently.
"An Admin updates a record. A Developer updates a List. We use Loops because we never know if we're dealing with 1 record or 200. Our code must be ready for both."
π Lab: The 20-Account Challengeβ
Let's build a system that generates data and then adds an "Intelligence Layer" to filter it. Open scripts/apex/hello.apex and try this:
// Step 1: Create a List (The Building)
List<Account> accountList = new List<Account>();
// Step 2: The Construction Layer (Build 10 records)
for (Integer x = 0; x < 10; x++) {
Account acc = new Account();
acc.Name = 'Account ' + x;
acc.NumberOfEmployees = x * 10;
accountList.add(acc);
System.debug('Added ' + acc.Name + ' to the list.');
}
// Step 3: The Intelligence Layer (Filter the data)
for(Account a : accountList) {
if(a.NumberOfEmployees > 50) {
System.debug('π₯ High Capacity Account: ' + a.Name);
}
}
π½οΈ The Revealβ
Notice what happened:
- We built 10 records in memory.
- We used logic to find only the ones with > 50 employees.
- We did it all in milliseconds.
This is the foundation of Bulkification. Whether you have 10 records or 10,000, this logic remains the same.
Good follow up resources in trailheads. I recommend going through and getting the following Badge.