You need to sign in to do that
Don't have an account?
Dippan Patel
Storing sensitive data using custom settings
Hi All,
I have hardcoded client id and client secret in my code. Salesforce review mentioned to use protected custom settings to store sensitive information.
So, I created a protected custom setting with two fields client id and client secret. I saved the values in it at Default Organization Level Value. This custom setting is added to my managed package.
I am able to access it in the developer org, but if my package is installed in another org, it returns null. Below is the code used to access the client id
I have hardcoded client id and client secret in my code. Salesforce review mentioned to use protected custom settings to store sensitive information.
So, I created a protected custom setting with two fields client id and client secret. I saved the values in it at Default Organization Level Value. This custom setting is added to my managed package.
I am able to access it in the developer org, but if my package is installed in another org, it returns null. Below is the code used to access the client id
Access_Key__c authTokenSetting = Access_Key__c.getOrgDefaults(); String rawcryptoKey = authTokenSetting.UniqueEntry__Crypto_Key__c; System.debug(LoggingLevel.DEBUG, 'Raw crypto key: ' + rawcryptoKey);
system.debug(Dreamhouse_Settings__c.getInstance());
system.debug(Dreamhouse_Settings__c.getInstance().name);
Dreamhouse_Settings__c is a heirarchy custom setting and getInstance return the complete record.
Dreamhouse_Settings__c.getInstance().name return the name of the record.
May be you can try to use list custom setting.
All Answers
Custom setting is like an object and your two fields value store as a data. When you move the apex code or custom setting from one org to another you need to add values in the custom setting.
Please insert the data and try.
Thanks for your reply. I've already added values in the custom setting by clicking on manage and then save. Do you mean this?
//getOrgDefaults() returning empty object/null when API >23.0, so update custom setting
if (Access_Key__c.getInstance() == null) {
upsert new Access_Key__c (SetupOwnerId = Userinfo.getOrganizationId()); // if get null update the setting
}
String rawcryptoKey = Access_Key__c.getInstance().UniqueEntry__Crypto_Key__c;
System.debug(LoggingLevel.DEBUG, 'Raw crypto key: ' + rawcryptoKey);
When I tried your code, Access_Key__c.getInstance() is not null so it doesn't upsert. But Access_Key__c.getInstance().UniqueEntry__Crypto_Key__c gives null.
Any idea why?
system.debug(Dreamhouse_Settings__c.getInstance());
system.debug(Dreamhouse_Settings__c.getInstance().name);
Dreamhouse_Settings__c is a heirarchy custom setting and getInstance return the complete record.
Dreamhouse_Settings__c.getInstance().name return the name of the record.
May be you can try to use list custom setting.