├── .prettierignore
├── force-app
├── main
│ └── default
│ │ └── classes
│ │ ├── ListUtils.cls-meta.xml
│ │ ├── SortableAccount.cls-meta.xml
│ │ ├── AccountRatingComparator.cls-meta.xml
│ │ ├── SObjectStringFieldComparator.cls-meta.xml
│ │ ├── ListUtils.cls
│ │ ├── SObjectStringFieldComparator.cls
│ │ ├── SortableAccount.cls
│ │ └── AccountRatingComparator.cls
└── test
│ └── default
│ └── classes
│ ├── SortableAccountTests.cls-meta.xml
│ ├── AccountRatingComparatorTests.cls-meta.xml
│ ├── SObjectStringFieldComparatorTests.cls-meta.xml
│ ├── SortableAccountTests.cls
│ ├── SObjectStringFieldComparatorTests.cls
│ └── AccountRatingComparatorTests.cls
├── sfdx-project.json
├── config
└── project-scratch-def.json
├── package.json
├── .gitignore
└── README.md
/.prettierignore:
--------------------------------------------------------------------------------
1 | # List files or directories below to ignore them when running prettier
2 | # More information: https://prettier.io/docs/en/ignore.html
3 | #
4 |
5 | .localdevserver
6 | .sfdx
7 | .vscode
8 | coverage/
--------------------------------------------------------------------------------
/force-app/main/default/classes/ListUtils.cls-meta.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 52.0
4 | Active
5 |
6 |
--------------------------------------------------------------------------------
/force-app/main/default/classes/SortableAccount.cls-meta.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 52.0
4 | Active
5 |
6 |
--------------------------------------------------------------------------------
/force-app/main/default/classes/AccountRatingComparator.cls-meta.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 52.0
4 | Active
5 |
6 |
--------------------------------------------------------------------------------
/force-app/test/default/classes/SortableAccountTests.cls-meta.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 52.0
4 | Active
5 |
6 |
--------------------------------------------------------------------------------
/force-app/main/default/classes/SObjectStringFieldComparator.cls-meta.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 52.0
4 | Active
5 |
6 |
--------------------------------------------------------------------------------
/force-app/test/default/classes/AccountRatingComparatorTests.cls-meta.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 52.0
4 | Active
5 |
6 |
--------------------------------------------------------------------------------
/force-app/test/default/classes/SObjectStringFieldComparatorTests.cls-meta.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 52.0
4 | Active
5 |
6 |
--------------------------------------------------------------------------------
/sfdx-project.json:
--------------------------------------------------------------------------------
1 | {
2 | "packageDirectories": [
3 | {
4 | "path": "force-app",
5 | "default": true
6 | }
7 | ],
8 | "name": "apex-sorting",
9 | "namespace": "",
10 | "sfdcLoginUrl": "https://login.salesforce.com",
11 | "sourceApiVersion": "52.0"
12 | }
13 |
--------------------------------------------------------------------------------
/config/project-scratch-def.json:
--------------------------------------------------------------------------------
1 | {
2 | "orgName": "apex-sorting",
3 | "edition": "Developer",
4 | "features": ["EnableSetPasswordInApi"],
5 | "settings": {
6 | "lightningExperienceSettings": {
7 | "enableS1DesktopEnabled": true
8 | },
9 | "mobileSettings": {
10 | "enableS1EncryptedStoragePref2": false
11 | }
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "salesforce-app",
3 | "private": true,
4 | "version": "1.0.0",
5 | "description": "Salesforce App",
6 | "scripts": {
7 | "prettier": "prettier --write \"**/*.{cls,cmp,component,css,html,js,json,md,page,trigger,xml,yaml,yml}\"",
8 | "prettier:verify": "prettier --list-different \"**/*.{cls,cmp,component,css,html,js,json,md,page,trigger,xml,yaml,yml}\""
9 | },
10 | "devDependencies": {
11 | "@prettier/plugin-xml": "^1.0.2",
12 | "prettier": "^2.3.2",
13 | "prettier-plugin-apex": "^1.10.0"
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # This file is used for Git repositories to specify intentionally untracked files that Git should ignore.
2 | # If you are not using git, you can delete this file. For more information see: https://git-scm.com/docs/gitignore
3 | # For useful gitignore templates see: https://github.com/github/gitignore
4 |
5 | # Salesforce cache
6 | .sfdx/
7 | .localdevserver/
8 |
9 | # LWC VSCode autocomplete
10 | **/lwc/jsconfig.json
11 |
12 | # LWC Jest coverage reports
13 | coverage/
14 |
15 | # Logs
16 | logs
17 | *.log
18 | npm-debug.log*
19 | yarn-debug.log*
20 | yarn-error.log*
21 |
22 | # Dependency directories
23 | node_modules/
24 |
25 | # Eslint cache
26 | .eslintcache
27 |
28 | # MacOS system files
29 | .DS_Store
30 |
31 | # Windows system files
32 | Thumbs.db
33 | ehthumbs.db
34 | [Dd]esktop.ini
35 | $RECYCLE.BIN/
36 |
37 | # Local environment variables
38 | .env
39 |
40 | # VSCode settings
41 | .vscode
42 |
--------------------------------------------------------------------------------
/force-app/test/default/classes/SortableAccountTests.cls:
--------------------------------------------------------------------------------
1 | @isTest
2 | public class SortableAccountTests {
3 | private final static Account a1 = new Account(ShippingCountry = 'A');
4 | private final static Account a2 = new Account(ShippingCountry = 'A');
5 | private final static Account a3 = new Account(ShippingCountry = 'B');
6 | private final static Account a4 = new Account(ShippingCountry = 'C');
7 |
8 | @isTest
9 | private static void sort_works() {
10 | List accounts = new List{ a4, a2, a3, a1 };
11 |
12 | SortableAccount.sort(accounts);
13 |
14 | List expected = new List{ a2, a1, a3, a4 };
15 | System.assertEquals(accounts, expected);
16 | }
17 |
18 | @isTest
19 | private static void compareTo_fails_when_incompatible_type() {
20 | SortableAccount sa1 = new SortableAccount(a1);
21 | Integer i = 1;
22 |
23 | try {
24 | sa1.compareTo(i);
25 | System.assert(false, 'Expected SortException');
26 | } catch (SortableAccount.SortException e) {
27 | System.assert(true);
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/force-app/main/default/classes/ListUtils.cls:
--------------------------------------------------------------------------------
1 | public class ListUtils {
2 | /**
3 | * Sorts a list of objects using bubble sort algorithm and a comparator
4 | */
5 | public static void sort(List