Skip to content

Commit 30ec6bb

Browse files
committed
refactoring
1 parent 1e3eedf commit 30ec6bb

26 files changed

+106
-259
lines changed

.eslintignore

Lines changed: 0 additions & 16 deletions
This file was deleted.

.forceignore

Lines changed: 0 additions & 12 deletions
This file was deleted.

.gitignore

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
1-
# This file is used for Git repositories to specify intentionally untracked files that Git should ignore.
1+
# This file is used for Git repositories to specify intentionally untracked files that Git should ignore.
22
# If you are not using git, you can delete this file. For more information see: https://git-scm.com/docs/gitignore
33
# For useful gitignore templates see: https://github.com/github/gitignore
44

5+
# IDE
6+
.idea/
7+
.project/
8+
.nx-cache
9+
.vscode/
10+
.prettierrc
11+
512
# Salesforce cache
613
.sf/
714
.sfdx/
815
.localdevserver/
916
deploy-options.json
1017

18+
# CumulusCI
19+
.cci/
20+
1121
# LWC VSCode autocomplete
1222
**/lwc/jsconfig.json
1323

@@ -20,6 +30,7 @@ logs
2030
npm-debug.log*
2131
yarn-debug.log*
2232
yarn-error.log*
33+
-local-*
2334

2435
# Dependency directories
2536
node_modules/
@@ -37,4 +48,10 @@ ehthumbs.db
3748
$RECYCLE.BIN/
3849

3950
# Local environment variables
40-
.env
51+
.env
52+
53+
# SOQL Query Results
54+
**/scripts/soql/query-results
55+
56+
#Private keys
57+
*.key

.prettierignore

Lines changed: 0 additions & 10 deletions
This file was deleted.

.prettierrc

Lines changed: 0 additions & 13 deletions
This file was deleted.

README.md

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,27 @@
1-
[More details TBD]
2-
31
# Consts
42

53
The framework that allows keeping your apex's consts in an ordered way.
64

5+
## Example
6+
7+
```java
8+
Account acc = new Account(
9+
Name = 'My Account',
10+
Type = Consts.ACCOUNT.TYPE.PROSPECT,
11+
Rating = Consts.ACCOUNT.RATING.HOT
12+
);
13+
```
14+
15+
```java
16+
System.debug(Consts.ACCOUNT.TYPE.PROSPECT); // 'Prospect'
17+
System.debug(Consts.ACCOUNT.RATING.HOT); // 'Hit'
18+
19+
System.debug(Consts.CONTACT.API_NAME); // 'Contact'
20+
System.debug(Consts.CONTACT.LEAD_SOURCE.WEB); // 'Web'
21+
22+
System.debug(Consts.OPPORTUNITY.TYPE.EXISTING_CUSTOMER_DOWNGRADE); // 'Existing Customer - Downgrade'
23+
```
24+
725
## How it works?
826

927
All concrete classes are created as a *singleton*, so each class is initialized once during the transaction. To decrease heap size getters and setters are in use. It means that class will be *initialized on demand*, not always. e.g execution of `Consts.ACCOUNT.TYPE.PROSPECT` will create instance of `AccountConsts` only, without creating `ContactConsts`.
@@ -12,12 +30,36 @@ Code Architecture is following *Open/Close* and *Single Responsibility Principle
1230

1331
## How to use?
1432

33+
### Create concrete consts class
34+
35+
- Create `INSTANCE` variable to keep class instance (singleton).
36+
- Create inner classes to order values.
37+
1538
```java
16-
System.debug(Consts.ACCOUNT.TYPE.PROSPECT); // 'Prospect'
17-
System.debug(Consts.ACCOUNT.RATING.HOT); // 'Hit'
39+
public class ContactConsts {
40+
public static final ContactConsts INSTANCE = new ContactConsts();
41+
42+
public final String API_NAME = Contact.sObjectType.getDescribe().getName();
43+
44+
public final Status STATUS = new Status();
1845

19-
System.debug(Consts.CONTACT.API_NAME); // 'Contact'
20-
System.debug(Consts.CONTACT.LEAD_SOURCE.WEB); // 'Web'
46+
public class Status {
47+
public final String IN_APPROVAL_PROCESS = 'In Approval Process';
48+
public final String ACTIVATED = 'Activated';
49+
public final String DRAFT = 'Draft';
50+
}
51+
}
52+
```
53+
54+
### Add concrete consts class to `Consts`
55+
56+
```java
57+
public class Consts {
2158

22-
System.debug(Consts.OPPORTUNITY.TYPE.EXISTING_CUSTOMER_DOWNGRADE); // 'Existing Customer - Downgrade'
59+
public static final ContactConsts CONTACT {
60+
get {
61+
return ContactConsts.INSTANCE;
62+
}
63+
}
64+
}
2365
```

force-app/main/default/classes/constants/Consts.cls renamed to force-app/main/default/classes/Consts.cls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
public with sharing class Consts {
1+
public class Consts {
22

33
public static final AccountConsts ACCOUNT {
44
get {
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
@IsTest
2+
public class ConstsTest {
3+
4+
@IsTest
5+
static void accountConsts() {
6+
Assert.areNotEqual(null, Consts.ACCOUNT);
7+
}
8+
9+
@IsTest
10+
static void contactConsts() {
11+
Assert.areNotEqual(null, Consts.CONTACT);
12+
}
13+
14+
@IsTest
15+
static void opportunityConsts() {
16+
Assert.areNotEqual(null, Consts.OPPORTUNITY);
17+
}
18+
19+
@IsTest
20+
static void profileConsts() {
21+
Assert.areNotEqual(null, Consts.PROFILE);
22+
}
23+
}

0 commit comments

Comments
 (0)