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.