---
title: "Salesforce Naming Convention"
url: "https://blog.beyondthecloud.dev/blog/salesforce-naming-convention"
author: "Piotr Gajek"
published: "2024-01-05"
updated: "2025-04-04"
tags: "naming convention in salesforce, salesforce naming convention"
---

# Salesforce Naming Convention

By [Piotr Gajek](https://blog.beyondthecloud.dev/author/piotr-gajek.md), January 5, 2024

## Introduction

Why naming convention is important?

* **Self-Documentation** – Meaningful names self-document your code. Clean code is like a story that you can read and follow. Appropriate variable naming helps avoid the need for comments.
* **Consistency** – Naming conventions should be consistent across the whole project. Developers know what to expect, which can aid in understanding and debugging.
* **Readability and Understandability** – Code is for humans, not machines. We understand the code we create, but we should also consider developers who will maintain our code later. A clear naming convention reduces confusion and facilitates logical understanding.
* **Maintainability** – Modifications are easier to make in code we understand. Even if the code is not working, but you can understand it, you can also fix it.

## Issue

> Any fool can write code that a computer can understand. Good programmers write code that humans can understand.  
> \~ Martin Fowler

Good naming is necessary for the code to be readable and maintainable.  
The problem is that a lot of developers do not follow proper naming conventions. Code is becoming messy and hard to understand. 

❌❌❌

```java
map<string, string> mapAcc = new map<string, string>();
```

```java
string temp1 = '...';
```

```java
public static void fun() {
    // ...
}
```

I really like an example from "Clean Code" by Robert Cecil Martin that shows the importance of proper naming convention:

❌❌❌

```java
public List<Integer> getThem() {
    List<Integer> list1 = new List<Integer>(); 
    for (Integer x : theList) {
        if (x == 4) {
            list1.add(x);
        } 
    }
    return list1;
}
```

✅✅✅

```java
public List<Integer> getFlaggedCells() {
    List<Integer> flaggedCells = new List<Integer>(); 
    for (Integer cell : gameBoard) {
        if (cell == FLAGGED) {
            flaggedCells.add(cell);
        } 
    }
    return flaggedCells;
}
```

## Best Practice

* **Use Intention-Revealing Name** – Ensure that each name answers critical questions: why does it exist, what is its purpose, and how is it utilized?
* **Avoid Disinformation** – Steer clear of names that may lead to confusion and misinterpretation.
* **Make Meaningful Distinctions** – Clarify the distinctions between terms, for instance, differentiate between `name` and `nameString`, or between `accounts` and `accountList`. Simplify variable names by eliminating unnecessary words such as `the`, `String`, or `List`.
* **Use Pronounceable Names** – As stated by the quote, "_If you can’t pronounce it, you can’t discuss it without sounding like an idiot_" \[1\]. Opt for names that are easy to pronounce, facilitating effective communication and code explanation.
* **Use Searchable Names** – Avoid the use of magic numbers that may confuse. Instead, employ `final` or `const` variables to explicitly convey your intentions, such as \`const WORK\_DAYS\_PER\_WEEK = 5;
* **Pick One Word per Concept** – particularly crucial in Apex programming, adhering to the principle of using one word per concept. Maintain consistency, for example, with names like `AccountSelector` and `ContactSelector` for services and utility classes.
* **Add Meaningful Context** – Provide contextual clarity, especially in classes. For instance, the `state` variable in the `Address` class should represent something distinct from the `state` variable in the `Shipping` class.

### UPPER CASE

When to use?

* SOQL Keywords
* [final and const](#snake%5Fcase)

❌❌❌

```sql
select id, name from account
```

✅✅✅

```sql
SELECT Id, Name FROM Account
```

### snake\_case

* **`const` and `final` variables** – only `const` that are stored as global const values

✅✅✅

```java
public static final String PARTNER_RECORD_TYPE = 'Partner';
```

```js
import { LightningElement } from 'lwc'

const COLUMNS = [
   // ...
];

export default class MyComponent extends LightningElement {
    columns = COLUMNS;
}
```

### PascalCase

* **Apex Class Name**

```java
public with sharing class MyController {
    //...
}
```

* **LWC Component Name**

```js
import { LightningElement } from "lwc";

export default class MyComponent extends LightningElement {
    //...
}
```

* [Primitive Data Type](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon%5Fapex%5Fprimitives.htm)

❌❌❌

```java
string userName = '...';
boolean isPartner = false;
id accountId = '...';
```

✅✅✅

```java
String userName = '...';
Boolean isPartner = false;
Id accountId = '...';
```

* **Collection Type**

❌❌❌

```java
list<string> accounts = new list<string>();
set<string> names = new set<string>();
map<id, account> idToAccount = new map<id, account>();
```

✅✅✅

```java
List<String> accounts = new List<String>();
Set<String> names = new Set<String>();
Map<Id, Account> idToAccount = new Map<Id, Account>();
```

* **Object Name**

❌❌❌

```java
account myAccount = new account(...);
contact myContact = new contact(...);
```

```sql
SELECT Id, Name FROM account
```

✅✅✅

```java
Account myAccount = new Account(...);
Contact myContact = new Contact(...);
```

```sql
SELECT Id, Name FROM Account
```

* **Field Name**

❌❌❌

```sql
SELECT id, name FROM Account
```

```java
account acc = new account(
   name = 'My Account',
   industry = 'IT'
);
```

✅✅✅

```sql
SELECT Id, Name FROM Account
```

```java
Account acc = new Account(
   Name = 'My Account',
   Industry = 'IT'
);
```

### camelCase

* **Methods**

```java
public String getUserId() {
    // ...
}
```

```js
handleClick(event) {
    // ...
}
```

* **Variables**

```js
let accountName = '...';
```

```java
Boolean isPartner = false;
```

---

If you have any questions feel free to ask in the comment section below. 🙂

Was it helpful? Check out our other great posts [here](https://beyondthecloud.dev/blog).

---

## References

* \[1\] Clean Code – Robert C. Martin
* \[2\] [Importance of Variable Naming](https://www.linkedin.com/pulse/importance-variable-naming-priyanka-hiranandani/)
* \[3\] [Naming conventions in programming – a review of scientific literature](https://makimo.com/blog/scientific-perspective-on-naming-in-programming)
