function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SabrentSabrent 

Hardcoding Picklist Value

In Object__c I have a picklist field called Campaign__c and one of the picklist values is 2014 Charity Run.

 

In my Apex code, how can i avoid hardcoding the Campaign__c value ?

 

 

list <Object__c> obj = [Select id,name, Account__c, Campaign__c

                                   from Object__c

                                   Where Campaign__c=:'2014 Charity Run'];

 

 

 

Is custom setting the way to go?

 

 

 

 

 

 

 

 

 

 

vbsvbs
Thats the way to go.
An alternative would be to setup a common class file to maintain all picklist value constants. You will need to define them as public static final string variables in order to access them directly using class name for e.g.
public static final String OBJECT_CAMPAIGN_VALUE1 = '2014 Charity Run';

Note: Manage your use of custom settings as these count against number of custom objects.
SabrentSabrent

Thanks.