5

I am creating a Apex class to report bugs to Bugsnag. This integration requires an API key as described in the documentation.

In other environments, I usually store this kind of information outside the code (i.e. .env file), so that I can easily change it without updating the source code.

I was wondering what would be the equivalent of an .env file or a .properties file when writing Apex classes.

SOLUTION

I've created a new Custom Setting Definition (Hierarchy) called BugsnagSettings__c with a Custom Field API_KEY__c.

Here is how I consume it inside my APEX class:

BugsnagSettings__c bugsnagSettings = BugsnagSettings__c.getOrgDefaults();
String apiKey = bugsnagSettings.API_Key__c;
6

To store configuration settings, we would typically use a Custom Setting or Custom Metadata. Both can be accessed in Apex Code, and both can be modified using the user interface without modifying code. There's slightly different semantics for each, so you'll want to read the documentation.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.