You need to sign in to do that
Don't have an account?
Sébastien Van Cutsem 8
Custom settings as environment variable ?
We would like to avoid to hardcode value in an apex class and use "environment variable". Is the use of custom settings the right way to do that ?
Today I created a custom settings containing 2 fields, an url and a authorization token. The values are differents from one sandbox to another, so I create one data set for each of my sandbox (dev-int-uat-prod). Now my problem is to know in wich sandbox am I ? To retrieve the right values from my custom setting and of course I don't want to hardcode it. I used UserInfo.getUserName().substringAfterLast('@').substringAfterLast('.') to retrieve the sandbox name but for production this code doesn't work, so can anyone help me on the best way to do that ?
Thanks in advance for your answers and your help.
Today I created a custom settings containing 2 fields, an url and a authorization token. The values are differents from one sandbox to another, so I create one data set for each of my sandbox (dev-int-uat-prod). Now my problem is to know in wich sandbox am I ? To retrieve the right values from my custom setting and of course I don't want to hardcode it. I used UserInfo.getUserName().substringAfterLast('@').substringAfterLast('.') to retrieve the sandbox name but for production this code doesn't work, so can anyone help me on the best way to do that ?
Thanks in advance for your answers and your help.
You can use org Id.
Which will be different in all orgs.
You can get that in apex code by UserInfo.getOrganizationId
in order to save in custom settting you can get the org Id from
Setup | Company Profile | Company Information
there you can find "Salesforce.com Organization ID"
Hope this might help you .
Thanks!!
You are making it complex.
Just follow the steps mentiond below :
1. Create a List custom setting with two fields.
2. After createing two fields , Click on Manage and create a new record of Custom setting.
3. Enter the value of two fields according to the organisation.
4. You will migrate this Custom Setting into different environments but in each environment you have to create records manually so you can enter the value of those two fields differently in each organisation
5. Please make sure that the name of the record which you are creating in each Environment is same as you will reference the record with this name.
6. Now use this custom setting record in your apex class.
Please let me know if you need more clarification on this.
Thanks,
Abhishek.
Custom metadata is the better approach then custom setting . I am not sure why you want to track which organisation you are ? how it will help you after knowing the organisation details .
Thanks
Manoj
You can deploy the custom Metadata and the other most important thing is that they get refreshed to sandboxes, so you don't need to create Apex classes to generate the default Custom Setting records.
Hope this is helpful to you.
Thanks
e.g., {!$Organization.Id} {!$Organization.Name}
Or, you could use SOQL on Organization:
[SELECT ID, Name FROM Organization]
If you have additional settings for each Org that you want to access in Apex, you can go for Custom Setting. Otherwise, it is fine to simply use the MyKFCExperience (https://www.mykfcexperience.us/)
Hi sebastien,
Your code is working for me.Pelase follow like below.
You can check using Anonymous Wondow in production developer console.
open developer console and Ctrl+E .
type your code like below.And excecute
System.debug(UserInfo.getUserName().substringAfterLast('@').substringAfterLast('.'));
Thanks!.