/Salesforce-Environment-Vars

A simple solution for managing environment variables in salesforce

Primary LanguageTypeScriptMIT LicenseMIT

Salesforce Environment Variables

A simple library for using Custom Metadata to manage simple Key/Value Environment variables

UI Demo

idea inspired by Ralph Callaway's work

Usage

install in org

Use SFDX to deploy to org

  1. git clone https://github.com/ChuckJonas/Salesforce-Environment-Vars.git
  2. cd Salesforce-Environment-Vars
  3. mkdir deploy
  4. sfdx force:source:convert -d deploy/
  5. sfdx force:mdapi:deploy -d deploy/ -u "YOUR_USERNAME_HERE" -l RunSpecifiedTests -r EnvTests

NOTE: This application comes with a custom user interface for easier management of the ENV Vars. If you'd prefer not to use it, delete the following before deploying:

  • force-app/main/default/pages
  • force-app/main/default/staticresources

Setup

If UI was installed, navigate to /apex/env_vars and setup your Environment Variables. Otherwise, just manage like any other CustomMetadata.

Notes

The following types are currently supported:

  • String
  • Integer
  • Decimal
  • Boolean: Format: true or false
  • String[]: Format: ["a","b","c"]
  • Map<String,String>: Format: {"456":"xyz","123":"abc"}

Access in apex

Use Env.get() to access by passing in the DeveloperName:

// cast to datatype
Integer retries = (Integer) Env.get('Account_Sync_Retries');
String[] types = (String[]) Env.get('Status_Types');

Contributing/Modifying

This project is built off the B.A.S.S. Stack. See Readme for details on how to develop.