How to reference parameters outside of Apex Class that can be configured by AdministratorTimezone in datetime field in Custom SettingGenerate set of Ids from a map, am I doing it right?Deploying the custom settings and accessing classes to ProdRecord Type Id not being recognized when checked against value in List Custom SettingList Custom Setting with getInstance() inconsistent based on API VersionPassing parameters from a Test Class into an APEX Class that is called on a Visualforce pageCustom Setting list to query filterHow do I use a Protected Custom Setting?How to Query 2 Objects Down Parent to Child SOQL in APEX ClassCustom Settings in test classes for Lookup fields(ID)
I reverse the source code, you negate the input!
What was an "insurance cover"?
What do these pins mean? Where should I plug them in?
Why does NASA publish all the results/data it gets?
Did Apollo carry and use WD40?
Norwegian refuses EU delay (4.7 hours) compensation because it turned out there was nothing wrong with the aircraft
How to ask a man to not take up more than one seat on public transport while avoiding conflict?
How to influence manager to not schedule team meetings during lunch?
What is the fastest way to do Array Table Lookup with an Integer Index?
What did the controller say during my approach to land (audio clip)?
Figuring out the frequency components using FFT
How do I clean sealant/silicon from a glass mirror?
Is there any reason nowadays to use a neon indicator lamp instead of an LED?
Can one guy with a duplicator initiate a nuclear apocalypse?
What do you do if you have developments on your paper during the long peer review process?
When does removing Goblin Warchief affect its cost reduction ability?
Which museums have artworks of all four ninja turtles' namesakes?
What is a Heptagon Number™?
In a jam session, when asked which key my non-transposing instrument (like a violin) is in, what do I answer?
The 100 soldier problem
Is this a Sherman, and if so what model?
How is the problem, G has no triangle in Logspace?
How to make interviewee comfortable interviewing in lounge chairs
Is Zack Morris's 'time stop' ability in "Saved By the Bell" a supernatural ability?
How to reference parameters outside of Apex Class that can be configured by Administrator
Timezone in datetime field in Custom SettingGenerate set of Ids from a map, am I doing it right?Deploying the custom settings and accessing classes to ProdRecord Type Id not being recognized when checked against value in List Custom SettingList Custom Setting with getInstance() inconsistent based on API VersionPassing parameters from a Test Class into an APEX Class that is called on a Visualforce pageCustom Setting list to query filterHow do I use a Protected Custom Setting?How to Query 2 Objects Down Parent to Child SOQL in APEX ClassCustom Settings in test classes for Lookup fields(ID)
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
Here is an example of the challenge I have faced multiple times. I was wondering if anyone could offer best practices on how they handle situations like these.
I have an apex class that process records. I want to store some parameters outside so that my administrator could modify these parameters in the future without modifying and deploying the Class.
Consider this example:
I have a class that processes records owned by Users of specific Profiles.
In my class I have an SOQL query:
List<Id> profileIds = _____________; //I want to reference these Ids.
List<Opportunity> liOpportunity = [Select Id....FROM Opportunity WHERE Owner.ProfileId IN: profileIds];
What I have done in the past is create a new List custom setting Config__c with a Custom Text Field to store the profile Ids called Value__c and comments__c.
Then I would create the following record:
In my Apex Class, now all I have to do is reference the Value field in the Custom Setting.
List<Id> profileIds = Config__c.getValues('ProfileIds').Value__c.split(';');
The advantages of this method are:
- Doesn't count towards governor limits
- Easily configurable without deployment if requirements change at a later date.
My questions are the following:
Is this an optimal way of doing this or is there a better way to accomplish this (with similar or greater advantages)?
Would it be better to use a Custom Metadata Type for this scenario?
I hope this is the correct forum / way to ask this question. If there is a problem with my question or it is unclear kindly comment and I will restructure the question.
apex customsetting configuration parameters
add a comment
|
Here is an example of the challenge I have faced multiple times. I was wondering if anyone could offer best practices on how they handle situations like these.
I have an apex class that process records. I want to store some parameters outside so that my administrator could modify these parameters in the future without modifying and deploying the Class.
Consider this example:
I have a class that processes records owned by Users of specific Profiles.
In my class I have an SOQL query:
List<Id> profileIds = _____________; //I want to reference these Ids.
List<Opportunity> liOpportunity = [Select Id....FROM Opportunity WHERE Owner.ProfileId IN: profileIds];
What I have done in the past is create a new List custom setting Config__c with a Custom Text Field to store the profile Ids called Value__c and comments__c.
Then I would create the following record:
In my Apex Class, now all I have to do is reference the Value field in the Custom Setting.
List<Id> profileIds = Config__c.getValues('ProfileIds').Value__c.split(';');
The advantages of this method are:
- Doesn't count towards governor limits
- Easily configurable without deployment if requirements change at a later date.
My questions are the following:
Is this an optimal way of doing this or is there a better way to accomplish this (with similar or greater advantages)?
Would it be better to use a Custom Metadata Type for this scenario?
I hope this is the correct forum / way to ask this question. If there is a problem with my question or it is unclear kindly comment and I will restructure the question.
apex customsetting configuration parameters
Nowadays, I would prefer to store on Custom Metadata Type, unless you have a strong reason to store on Custom Settings.
– Jeferson Chaves
9 hours ago
add a comment
|
Here is an example of the challenge I have faced multiple times. I was wondering if anyone could offer best practices on how they handle situations like these.
I have an apex class that process records. I want to store some parameters outside so that my administrator could modify these parameters in the future without modifying and deploying the Class.
Consider this example:
I have a class that processes records owned by Users of specific Profiles.
In my class I have an SOQL query:
List<Id> profileIds = _____________; //I want to reference these Ids.
List<Opportunity> liOpportunity = [Select Id....FROM Opportunity WHERE Owner.ProfileId IN: profileIds];
What I have done in the past is create a new List custom setting Config__c with a Custom Text Field to store the profile Ids called Value__c and comments__c.
Then I would create the following record:
In my Apex Class, now all I have to do is reference the Value field in the Custom Setting.
List<Id> profileIds = Config__c.getValues('ProfileIds').Value__c.split(';');
The advantages of this method are:
- Doesn't count towards governor limits
- Easily configurable without deployment if requirements change at a later date.
My questions are the following:
Is this an optimal way of doing this or is there a better way to accomplish this (with similar or greater advantages)?
Would it be better to use a Custom Metadata Type for this scenario?
I hope this is the correct forum / way to ask this question. If there is a problem with my question or it is unclear kindly comment and I will restructure the question.
apex customsetting configuration parameters
Here is an example of the challenge I have faced multiple times. I was wondering if anyone could offer best practices on how they handle situations like these.
I have an apex class that process records. I want to store some parameters outside so that my administrator could modify these parameters in the future without modifying and deploying the Class.
Consider this example:
I have a class that processes records owned by Users of specific Profiles.
In my class I have an SOQL query:
List<Id> profileIds = _____________; //I want to reference these Ids.
List<Opportunity> liOpportunity = [Select Id....FROM Opportunity WHERE Owner.ProfileId IN: profileIds];
What I have done in the past is create a new List custom setting Config__c with a Custom Text Field to store the profile Ids called Value__c and comments__c.
Then I would create the following record:
In my Apex Class, now all I have to do is reference the Value field in the Custom Setting.
List<Id> profileIds = Config__c.getValues('ProfileIds').Value__c.split(';');
The advantages of this method are:
- Doesn't count towards governor limits
- Easily configurable without deployment if requirements change at a later date.
My questions are the following:
Is this an optimal way of doing this or is there a better way to accomplish this (with similar or greater advantages)?
Would it be better to use a Custom Metadata Type for this scenario?
I hope this is the correct forum / way to ask this question. If there is a problem with my question or it is unclear kindly comment and I will restructure the question.
apex customsetting configuration parameters
apex customsetting configuration parameters
asked 10 hours ago
Z33dawgZ33dawg
37010 bronze badges
37010 bronze badges
Nowadays, I would prefer to store on Custom Metadata Type, unless you have a strong reason to store on Custom Settings.
– Jeferson Chaves
9 hours ago
add a comment
|
Nowadays, I would prefer to store on Custom Metadata Type, unless you have a strong reason to store on Custom Settings.
– Jeferson Chaves
9 hours ago
Nowadays, I would prefer to store on Custom Metadata Type, unless you have a strong reason to store on Custom Settings.
– Jeferson Chaves
9 hours ago
Nowadays, I would prefer to store on Custom Metadata Type, unless you have a strong reason to store on Custom Settings.
– Jeferson Chaves
9 hours ago
add a comment
|
1 Answer
1
active
oldest
votes
Is this an optimal way of doing this or is there a better way to accomplish this (with similar or greater advantages)/Would it be better to use a Custom Metadata Type for this scenario?
I would use custom metadata types for the following reason.
- We can use SOQL, and each profile ID can be a record of custom metadata. SOQL on custom metadata are not counted towards the governor SOQL limit
- Can be configured directly in prod. No need of deployment
- Can be source controlled as its a metadata, that mean you will retain history of what was the older value if you use Version control like GIT or SVN
- Can be deployed using ant and change set. You dont have to worry about moving them as they can also be packaged(read unmanaged, managed, unlocked etc)
- Can have relationships to other custom metadata records
- Can have entity deifinition and field definition to Standard/Custom Object and fields.
1
+1. One thing to note -- if you're used to working with Custom Settings, you'll need to think differently about Custom Metadata when it comes to test classes. Whereas you can (must) create specific Custom Settings in a test class, You cannot change Custom Metadata within your test class... you must use what is specified in your custom metadata.
– Chris Johnson
9 hours ago
Thanks, I see the benefits of using MDT's. in my scenario considering I created a record of custom mdt for each profile Id, how would you recommend an admin be able to select which profiles I would like to use in my class. I imagine you are implying that the admin create the MDT records if they want to be used or delete them if they should no longer be used. Could you elaborate?
– Z33dawg
9 hours ago
My Idea I guess would be to create a MDT Object likeApex_Config__mdt
. I could then create custom fields such as a multiselect picklist Profiles__c (label: profile_name, value profile_id) , a comment field (to explain which fields to configure) Then I can create records of which I can query from classes. In my class I would query for the appropriate record and uses the field values. I could then reuse this model for different classes. Anyone have better ideas?
– Z33dawg
8 hours ago
@Z33dawg that sounds ideal :)
– Pranay Jaiswal
8 hours ago
LOL I just checked and [obviously] for some reason, Salesforce does not support multi select picklists on custom MDT.
– Z33dawg
7 hours ago
|
show 1 more comment
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "459"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f278604%2fhow-to-reference-parameters-outside-of-apex-class-that-can-be-configured-by-admi%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Is this an optimal way of doing this or is there a better way to accomplish this (with similar or greater advantages)/Would it be better to use a Custom Metadata Type for this scenario?
I would use custom metadata types for the following reason.
- We can use SOQL, and each profile ID can be a record of custom metadata. SOQL on custom metadata are not counted towards the governor SOQL limit
- Can be configured directly in prod. No need of deployment
- Can be source controlled as its a metadata, that mean you will retain history of what was the older value if you use Version control like GIT or SVN
- Can be deployed using ant and change set. You dont have to worry about moving them as they can also be packaged(read unmanaged, managed, unlocked etc)
- Can have relationships to other custom metadata records
- Can have entity deifinition and field definition to Standard/Custom Object and fields.
1
+1. One thing to note -- if you're used to working with Custom Settings, you'll need to think differently about Custom Metadata when it comes to test classes. Whereas you can (must) create specific Custom Settings in a test class, You cannot change Custom Metadata within your test class... you must use what is specified in your custom metadata.
– Chris Johnson
9 hours ago
Thanks, I see the benefits of using MDT's. in my scenario considering I created a record of custom mdt for each profile Id, how would you recommend an admin be able to select which profiles I would like to use in my class. I imagine you are implying that the admin create the MDT records if they want to be used or delete them if they should no longer be used. Could you elaborate?
– Z33dawg
9 hours ago
My Idea I guess would be to create a MDT Object likeApex_Config__mdt
. I could then create custom fields such as a multiselect picklist Profiles__c (label: profile_name, value profile_id) , a comment field (to explain which fields to configure) Then I can create records of which I can query from classes. In my class I would query for the appropriate record and uses the field values. I could then reuse this model for different classes. Anyone have better ideas?
– Z33dawg
8 hours ago
@Z33dawg that sounds ideal :)
– Pranay Jaiswal
8 hours ago
LOL I just checked and [obviously] for some reason, Salesforce does not support multi select picklists on custom MDT.
– Z33dawg
7 hours ago
|
show 1 more comment
Is this an optimal way of doing this or is there a better way to accomplish this (with similar or greater advantages)/Would it be better to use a Custom Metadata Type for this scenario?
I would use custom metadata types for the following reason.
- We can use SOQL, and each profile ID can be a record of custom metadata. SOQL on custom metadata are not counted towards the governor SOQL limit
- Can be configured directly in prod. No need of deployment
- Can be source controlled as its a metadata, that mean you will retain history of what was the older value if you use Version control like GIT or SVN
- Can be deployed using ant and change set. You dont have to worry about moving them as they can also be packaged(read unmanaged, managed, unlocked etc)
- Can have relationships to other custom metadata records
- Can have entity deifinition and field definition to Standard/Custom Object and fields.
1
+1. One thing to note -- if you're used to working with Custom Settings, you'll need to think differently about Custom Metadata when it comes to test classes. Whereas you can (must) create specific Custom Settings in a test class, You cannot change Custom Metadata within your test class... you must use what is specified in your custom metadata.
– Chris Johnson
9 hours ago
Thanks, I see the benefits of using MDT's. in my scenario considering I created a record of custom mdt for each profile Id, how would you recommend an admin be able to select which profiles I would like to use in my class. I imagine you are implying that the admin create the MDT records if they want to be used or delete them if they should no longer be used. Could you elaborate?
– Z33dawg
9 hours ago
My Idea I guess would be to create a MDT Object likeApex_Config__mdt
. I could then create custom fields such as a multiselect picklist Profiles__c (label: profile_name, value profile_id) , a comment field (to explain which fields to configure) Then I can create records of which I can query from classes. In my class I would query for the appropriate record and uses the field values. I could then reuse this model for different classes. Anyone have better ideas?
– Z33dawg
8 hours ago
@Z33dawg that sounds ideal :)
– Pranay Jaiswal
8 hours ago
LOL I just checked and [obviously] for some reason, Salesforce does not support multi select picklists on custom MDT.
– Z33dawg
7 hours ago
|
show 1 more comment
Is this an optimal way of doing this or is there a better way to accomplish this (with similar or greater advantages)/Would it be better to use a Custom Metadata Type for this scenario?
I would use custom metadata types for the following reason.
- We can use SOQL, and each profile ID can be a record of custom metadata. SOQL on custom metadata are not counted towards the governor SOQL limit
- Can be configured directly in prod. No need of deployment
- Can be source controlled as its a metadata, that mean you will retain history of what was the older value if you use Version control like GIT or SVN
- Can be deployed using ant and change set. You dont have to worry about moving them as they can also be packaged(read unmanaged, managed, unlocked etc)
- Can have relationships to other custom metadata records
- Can have entity deifinition and field definition to Standard/Custom Object and fields.
Is this an optimal way of doing this or is there a better way to accomplish this (with similar or greater advantages)/Would it be better to use a Custom Metadata Type for this scenario?
I would use custom metadata types for the following reason.
- We can use SOQL, and each profile ID can be a record of custom metadata. SOQL on custom metadata are not counted towards the governor SOQL limit
- Can be configured directly in prod. No need of deployment
- Can be source controlled as its a metadata, that mean you will retain history of what was the older value if you use Version control like GIT or SVN
- Can be deployed using ant and change set. You dont have to worry about moving them as they can also be packaged(read unmanaged, managed, unlocked etc)
- Can have relationships to other custom metadata records
- Can have entity deifinition and field definition to Standard/Custom Object and fields.
edited 9 hours ago
answered 9 hours ago
Pranay JaiswalPranay Jaiswal
24.5k5 gold badges35 silver badges77 bronze badges
24.5k5 gold badges35 silver badges77 bronze badges
1
+1. One thing to note -- if you're used to working with Custom Settings, you'll need to think differently about Custom Metadata when it comes to test classes. Whereas you can (must) create specific Custom Settings in a test class, You cannot change Custom Metadata within your test class... you must use what is specified in your custom metadata.
– Chris Johnson
9 hours ago
Thanks, I see the benefits of using MDT's. in my scenario considering I created a record of custom mdt for each profile Id, how would you recommend an admin be able to select which profiles I would like to use in my class. I imagine you are implying that the admin create the MDT records if they want to be used or delete them if they should no longer be used. Could you elaborate?
– Z33dawg
9 hours ago
My Idea I guess would be to create a MDT Object likeApex_Config__mdt
. I could then create custom fields such as a multiselect picklist Profiles__c (label: profile_name, value profile_id) , a comment field (to explain which fields to configure) Then I can create records of which I can query from classes. In my class I would query for the appropriate record and uses the field values. I could then reuse this model for different classes. Anyone have better ideas?
– Z33dawg
8 hours ago
@Z33dawg that sounds ideal :)
– Pranay Jaiswal
8 hours ago
LOL I just checked and [obviously] for some reason, Salesforce does not support multi select picklists on custom MDT.
– Z33dawg
7 hours ago
|
show 1 more comment
1
+1. One thing to note -- if you're used to working with Custom Settings, you'll need to think differently about Custom Metadata when it comes to test classes. Whereas you can (must) create specific Custom Settings in a test class, You cannot change Custom Metadata within your test class... you must use what is specified in your custom metadata.
– Chris Johnson
9 hours ago
Thanks, I see the benefits of using MDT's. in my scenario considering I created a record of custom mdt for each profile Id, how would you recommend an admin be able to select which profiles I would like to use in my class. I imagine you are implying that the admin create the MDT records if they want to be used or delete them if they should no longer be used. Could you elaborate?
– Z33dawg
9 hours ago
My Idea I guess would be to create a MDT Object likeApex_Config__mdt
. I could then create custom fields such as a multiselect picklist Profiles__c (label: profile_name, value profile_id) , a comment field (to explain which fields to configure) Then I can create records of which I can query from classes. In my class I would query for the appropriate record and uses the field values. I could then reuse this model for different classes. Anyone have better ideas?
– Z33dawg
8 hours ago
@Z33dawg that sounds ideal :)
– Pranay Jaiswal
8 hours ago
LOL I just checked and [obviously] for some reason, Salesforce does not support multi select picklists on custom MDT.
– Z33dawg
7 hours ago
1
1
+1. One thing to note -- if you're used to working with Custom Settings, you'll need to think differently about Custom Metadata when it comes to test classes. Whereas you can (must) create specific Custom Settings in a test class, You cannot change Custom Metadata within your test class... you must use what is specified in your custom metadata.
– Chris Johnson
9 hours ago
+1. One thing to note -- if you're used to working with Custom Settings, you'll need to think differently about Custom Metadata when it comes to test classes. Whereas you can (must) create specific Custom Settings in a test class, You cannot change Custom Metadata within your test class... you must use what is specified in your custom metadata.
– Chris Johnson
9 hours ago
Thanks, I see the benefits of using MDT's. in my scenario considering I created a record of custom mdt for each profile Id, how would you recommend an admin be able to select which profiles I would like to use in my class. I imagine you are implying that the admin create the MDT records if they want to be used or delete them if they should no longer be used. Could you elaborate?
– Z33dawg
9 hours ago
Thanks, I see the benefits of using MDT's. in my scenario considering I created a record of custom mdt for each profile Id, how would you recommend an admin be able to select which profiles I would like to use in my class. I imagine you are implying that the admin create the MDT records if they want to be used or delete them if they should no longer be used. Could you elaborate?
– Z33dawg
9 hours ago
My Idea I guess would be to create a MDT Object like
Apex_Config__mdt
. I could then create custom fields such as a multiselect picklist Profiles__c (label: profile_name, value profile_id) , a comment field (to explain which fields to configure) Then I can create records of which I can query from classes. In my class I would query for the appropriate record and uses the field values. I could then reuse this model for different classes. Anyone have better ideas?– Z33dawg
8 hours ago
My Idea I guess would be to create a MDT Object like
Apex_Config__mdt
. I could then create custom fields such as a multiselect picklist Profiles__c (label: profile_name, value profile_id) , a comment field (to explain which fields to configure) Then I can create records of which I can query from classes. In my class I would query for the appropriate record and uses the field values. I could then reuse this model for different classes. Anyone have better ideas?– Z33dawg
8 hours ago
@Z33dawg that sounds ideal :)
– Pranay Jaiswal
8 hours ago
@Z33dawg that sounds ideal :)
– Pranay Jaiswal
8 hours ago
LOL I just checked and [obviously] for some reason, Salesforce does not support multi select picklists on custom MDT.
– Z33dawg
7 hours ago
LOL I just checked and [obviously] for some reason, Salesforce does not support multi select picklists on custom MDT.
– Z33dawg
7 hours ago
|
show 1 more comment
Thanks for contributing an answer to Salesforce Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f278604%2fhow-to-reference-parameters-outside-of-apex-class-that-can-be-configured-by-admi%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Nowadays, I would prefer to store on Custom Metadata Type, unless you have a strong reason to store on Custom Settings.
– Jeferson Chaves
9 hours ago