├── .gitignore ├── LICENSE ├── README.md ├── config └── project-scratch-def.json ├── force-app └── main │ └── default │ └── classes │ ├── Consts.cls │ ├── Consts.cls-meta.xml │ ├── ConstsTest.cls │ ├── ConstsTest.cls-meta.xml │ └── concrete-consts │ ├── AccountConsts.cls │ ├── AccountConsts.cls-meta.xml │ ├── ContactConsts.cls │ ├── ContactConsts.cls-meta.xml │ ├── OpportunityConsts.cls │ ├── OpportunityConsts.cls-meta.xml │ ├── ProfileConsts.cls │ └── ProfileConsts.cls-meta.xml ├── package.json └── sfdx-project.json /.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 | # IDE 6 | .idea/ 7 | .project/ 8 | .nx-cache 9 | .vscode/ 10 | .prettierrc 11 | 12 | # Salesforce cache 13 | .sf/ 14 | .sfdx/ 15 | .localdevserver/ 16 | deploy-options.json 17 | 18 | # CumulusCI 19 | .cci/ 20 | 21 | # LWC VSCode autocomplete 22 | **/lwc/jsconfig.json 23 | 24 | # LWC Jest coverage reports 25 | coverage/ 26 | 27 | # Logs 28 | logs 29 | *.log 30 | npm-debug.log* 31 | yarn-debug.log* 32 | yarn-error.log* 33 | -local-* 34 | 35 | # Dependency directories 36 | node_modules/ 37 | 38 | # Eslint cache 39 | .eslintcache 40 | 41 | # MacOS system files 42 | .DS_Store 43 | 44 | # Windows system files 45 | Thumbs.db 46 | ehthumbs.db 47 | [Dd]esktop.ini 48 | $RECYCLE.BIN/ 49 | 50 | # Local environment variables 51 | .env 52 | 53 | # SOQL Query Results 54 | **/scripts/soql/query-results 55 | 56 | #Private keys 57 | *.key 58 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Beyond The Cloud Dev 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Consts 2 | 3 | The Constants Framework provides a structured approach for managing constants in the Apex. 4 | 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 | 25 | ## How it works? 26 | 27 | The framework employs the concept of singletons to create concrete classes. 28 | Each class is initialized once during the transaction, reducing heap size usage. 29 | 30 | Getters and setters are used to lazily initialize the classes. 31 | For example, accessing `Consts.Account.TYPE.PROSPECT` will only create an instance of the `AccountConsts` class without creating `ContactConsts`. 32 | 33 | The code architecture follows the Open/Closed and Single Responsibility Principle principles. 34 | This design ensures the code is easily extensible, and each class is responsible for a specific set of constants. 35 | 36 | ## How to use it? 37 | 38 | ### Create a concrete consts class 39 | 40 | - Define an `INSTANCE` variable to hold the class instance (singleton). 41 | - Create inner classes to organize the constant values. 42 | 43 | ```java 44 | public class ContactConsts { 45 | public static final ContactConsts INSTANCE = new ContactConsts(); 46 | 47 | public final String API_NAME = Contact.sObjectType.getDescribe().getName(); 48 | 49 | public final Status STATUS = new Status(); 50 | 51 | public class Status { 52 | public final String IN_APPROVAL_PROCESS = 'In Approval Process'; 53 | public final String ACTIVATED = 'Activated'; 54 | public final String DRAFT = 'Draft'; 55 | } 56 | } 57 | ``` 58 | 59 | ### Add a concrete consts class to `Consts` 60 | 61 | ```java 62 | public class Consts { 63 | 64 | public static final ContactConsts CONTACT { 65 | get { 66 | return ContactConsts.INSTANCE; 67 | } 68 | } 69 | } 70 | ``` 71 | -------------------------------------------------------------------------------- /config/project-scratch-def.json: -------------------------------------------------------------------------------- 1 | { 2 | "orgName": "piotr.gajek company", 3 | "edition": "Developer", 4 | "features": ["EnableSetPasswordInApi"], 5 | "settings": { 6 | "lightningExperienceSettings": { 7 | "enableS1DesktopEnabled": true 8 | }, 9 | "mobileSettings": { 10 | "enableS1EncryptedStoragePref2": false 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /force-app/main/default/classes/Consts.cls: -------------------------------------------------------------------------------- 1 | public class Consts { 2 | 3 | public static final AccountConsts ACCOUNT { 4 | get { 5 | return AccountConsts.INSTANCE; 6 | } 7 | } 8 | 9 | public static final ContactConsts CONTACT { 10 | get { 11 | return ContactConsts.INSTANCE; 12 | } 13 | } 14 | 15 | public static final OpportunityConsts OPPORTUNITY { 16 | get { 17 | return OpportunityConsts.INSTANCE; 18 | } 19 | } 20 | 21 | public static final ProfileConsts PROFILE { 22 | get { 23 | return ProfileConsts.INSTANCE; 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /force-app/main/default/classes/Consts.cls-meta.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 55.0 4 | Active 5 | 6 | -------------------------------------------------------------------------------- /force-app/main/default/classes/ConstsTest.cls: -------------------------------------------------------------------------------- 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 | } 24 | -------------------------------------------------------------------------------- /force-app/main/default/classes/ConstsTest.cls-meta.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 55.0 4 | Active 5 | 6 | -------------------------------------------------------------------------------- /force-app/main/default/classes/concrete-consts/AccountConsts.cls: -------------------------------------------------------------------------------- 1 | public class AccountConsts { 2 | public static final AccountConsts INSTANCE = new AccountConsts(); 3 | 4 | public final String API_NAME = Account.sObjectType.getDescribe().getName(); 5 | 6 | public final Type TYPE = new Type(); 7 | public final Rating RATING = new Rating(); 8 | 9 | public class Type { 10 | public final String CHANNEL_PARTNER_RESELLER = 'Channel Partner / Reseller'; 11 | public final String CUSTOMER_CHANNEL = 'Customer - Channel'; 12 | public final String CUSTOMER_DIRECT = 'Customer - Direct'; 13 | public final String INSTALLATION_PARTNER = 'Installation Partner'; 14 | public final String OTHER = 'Other'; 15 | public final String PROSPECT = 'Prospect'; 16 | public final String TECHNOLOGY_PARTNER = 'Technology Partner'; 17 | } 18 | 19 | public class Rating { 20 | public final String COLD = 'Cold'; 21 | public final String HOT = 'Hot'; 22 | public final String WARM = 'Warm'; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /force-app/main/default/classes/concrete-consts/AccountConsts.cls-meta.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 55.0 4 | Active 5 | 6 | -------------------------------------------------------------------------------- /force-app/main/default/classes/concrete-consts/ContactConsts.cls: -------------------------------------------------------------------------------- 1 | public class ContactConsts { 2 | public static final ContactConsts INSTANCE = new ContactConsts(); 3 | 4 | public final String API_NAME = Contact.sObjectType.getDescribe().getName(); 5 | 6 | public final Status STATUS = new Status(); 7 | 8 | public class Status { 9 | public final String IN_APPROVAL_PROCESS = 'In Approval Process'; 10 | public final String ACTIVATED = 'Activated'; 11 | public final String DRAFT = 'Draft'; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /force-app/main/default/classes/concrete-consts/ContactConsts.cls-meta.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 55.0 4 | Active 5 | 6 | -------------------------------------------------------------------------------- /force-app/main/default/classes/concrete-consts/OpportunityConsts.cls: -------------------------------------------------------------------------------- 1 | public class OpportunityConsts { 2 | public static final OpportunityConsts INSTANCE = new OpportunityConsts(); 3 | 4 | public final String API_NAME = Opportunity.sObjectType.getDescribe().getName(); 5 | 6 | public final Type TYPE = new Type(); 7 | 8 | public class Type { 9 | public final String CHANNEL_PARTNER_RESELLER = 'Channel Partner / Reseller'; 10 | public final String EXISTING_CUSTOMER_DOWNGRADE = 'Existing Customer - Downgrade'; 11 | public final String EXISTING_CUSTOMER_REPLACEMENT = 'Existing Customer - Replacement'; 12 | public final String EXISTING_CUSTOMER_UPGRADE = 'Existing Customer - Upgrade'; 13 | public final String NEW_CUSTOMER = 'New Customer'; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /force-app/main/default/classes/concrete-consts/OpportunityConsts.cls-meta.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 55.0 4 | Active 5 | 6 | -------------------------------------------------------------------------------- /force-app/main/default/classes/concrete-consts/ProfileConsts.cls: -------------------------------------------------------------------------------- 1 | public class ProfileConsts { 2 | public static final ProfileConsts INSTANCE = new ProfileConsts(); 3 | 4 | public final Name NAME = new Name(); 5 | 6 | public class Name { 7 | public final String ANALYTICS_CLOUD_INTEGRATION_USER = 'Analytics Cloud Integration User'; 8 | public final String ANALYTICS_CLOUD_SECURITY_USER = 'Analytics Cloud Security User'; 9 | public final String AUTHENTICATED_WEBSITE = 'Authenticated Website'; 10 | public final String CHATTER_EXTERNAL_USER = 'Chatter External User'; 11 | public final String CHATTER_FREE_USER = 'Chatter Free User'; 12 | public final String CHATTER_MODERATOR_USER = 'Chatter Moderator User'; 13 | public final String COMMUNITY_PROFILE = 'Community Profile'; 14 | public final String CONTRACT_MANAGER = 'Contract Manager'; 15 | public final String CROSS_ORG_DATA_PROXY_USER = 'Cross Org Data Proxy User'; 16 | public final String CUSETOMER_PORTAL_MANAGER_CUSTOM = 'Customer Portal Manager Custom'; 17 | public final String CUSTOMER_COMMUNITY_LOGIN_USER = 'Customer Community Login User'; 18 | public final String CUSTOMER_COMMUNITY_PLUS_LOGIN_USER = 'Customer Community Plus Login User'; 19 | public final String CUSTOMER_COMMUNITY_PLUS_USER = 'Customer Community Plus User'; 20 | public final String CUSTOMER_COMMUNITY_USER = 'Customer Community User'; 21 | public final String CUSTOMER_PORTAL_MANAGER_STANDARD = 'Customer Portal Manager Standard'; 22 | public final String EXTERNAL_APPS_LOGIN_USER = 'External Apps Login User'; 23 | public final String EXTERNAL_IDENTITY_USER = 'External Identity User'; 24 | public final String FORCE_COM_APP_SUBSCRIPTION_USER = 'Force.com - App Subscription User'; 25 | public final String FORCE_COM_FREE_USER = 'Force.com - Free User'; 26 | public final String GOLD_PARTNER_USER = 'Gold Partner User'; 27 | public final String HIGHT_VOLUMNE_CUSTOMER_PORTAL_USER = 'High Volume Customer Portal User'; 28 | public final String HIGH_VOLUME_CUSTOMER_PORTAL = 'High Volume Customer Portal'; 29 | public final String IDENTITY_USER = 'Identity User'; 30 | public final String MARKETING_USER = 'Marketing User'; 31 | public final String MINIMUM_ACCESS_SALESFORCE = 'Minimum Access - Salesforce'; 32 | public final String PARTNER_APP_SUBSCRIPTION_USER = 'Partner App Subscription User'; 33 | public final String PARTNER_COMMUNITY_LOGIN_USER = 'Partner Community Login User'; 34 | public final String PARTNER_COMMUNITY_USER = 'Partner Community User'; 35 | public final String READ_ONLY = 'Read Only'; 36 | public final String SILVER_PARTNER_USER = 'Silver Partner User'; 37 | public final String SOLUTION_MANAGER = 'Solution Manager'; 38 | public final String STANDARD_GUEST = 'Standard Guest'; 39 | public final String STANDARD_PLATFORM_USER = 'Standard Platform User'; 40 | public final String STANDARD_USER = 'Standard User'; 41 | public final String SYSTEM_ADMINSTRATOR = 'System Administrator'; 42 | public final String WORK_COM_ONLY_USER = 'Work.com Only User'; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /force-app/main/default/classes/concrete-consts/ProfileConsts.cls-meta.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 55.0 4 | Active 5 | 6 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "salesforce-app", 3 | "private": true, 4 | "version": "1.0.0", 5 | "description": "Salesforce App", 6 | "scripts": { 7 | "lint": "eslint **/{aura,lwc}/**", 8 | "test": "npm run test:unit", 9 | "test:unit": "sfdx-lwc-jest", 10 | "test:unit:watch": "sfdx-lwc-jest --watch", 11 | "test:unit:debug": "sfdx-lwc-jest --debug", 12 | "test:unit:coverage": "sfdx-lwc-jest --coverage", 13 | "prettier": "prettier --write \"**/*.{cls,cmp,component,css,html,js,json,md,page,trigger,xml,yaml,yml}\"", 14 | "prettier:verify": "prettier --list-different \"**/*.{cls,cmp,component,css,html,js,json,md,page,trigger,xml,yaml,yml}\"", 15 | "postinstall": "husky install", 16 | "precommit": "lint-staged" 17 | }, 18 | "devDependencies": { 19 | "@lwc/eslint-plugin-lwc": "^1.1.2", 20 | "@prettier/plugin-xml": "^2.0.1", 21 | "@salesforce/eslint-config-lwc": "^3.2.3", 22 | "@salesforce/eslint-plugin-aura": "^2.0.0", 23 | "@salesforce/eslint-plugin-lightning": "^1.0.0", 24 | "@salesforce/sfdx-lwc-jest": "^1.1.0", 25 | "eslint": "^8.11.0", 26 | "eslint-plugin-import": "^2.25.4", 27 | "eslint-plugin-jest": "^26.1.2", 28 | "husky": "^7.0.4", 29 | "lint-staged": "^12.3.7", 30 | "prettier": "^2.6.0", 31 | "prettier-plugin-apex": "^1.10.0" 32 | }, 33 | "lint-staged": { 34 | "**/*.{cls,cmp,component,css,html,js,json,md,page,trigger,xml,yaml,yml}": [ 35 | "prettier --write" 36 | ], 37 | "**/{aura,lwc}/**": [ 38 | "eslint" 39 | ] 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /sfdx-project.json: -------------------------------------------------------------------------------- 1 | { 2 | "packageDirectories": [ 3 | { 4 | "path": "force-app", 5 | "default": true 6 | } 7 | ], 8 | "name": "apex-consts", 9 | "namespace": "", 10 | "sfdcLoginUrl": "https://login.salesforce.com", 11 | "sourceApiVersion": "55.0" 12 | } 13 | --------------------------------------------------------------------------------