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

select picklist values

my custom field Restaurant__c is defined as a picklist.
I want to read the values ​​of the list in my  execute part of my code.
how does the best?

global Database.QueryLocator start(Database.BatchableContext BC)
        Date d =;
        String query = 'SELECT Account__c,Lieferkosten__c,Preis__c,Restaurant__c,Kunde__c FROM Order__c WHERE DatumZeit__c < :d';
        return Database.getQueryLocator(query);

global void execute(Database.BatchableContext BC, List<Sobject> scope)
    {    .....
Phillip SouthernPhillip Southern
Hi, if its a single select value picklist...then in apex it will just be a string returned in your query.  If its a multipicklist, you will still get a string return, but the values will be seperated by a for example:


Either way, refernce the field in your query and object like normal.
Thank you. Can you help me with the script?
In the list is always only one possible value.
Phillip SouthernPhillip Southern
Hi, just add it to your query....i'm not sure what your field name for this example let's say its your query would change to:

String query = 'SELECT Account__c,Lieferkosten__c,Preis__c,Restaurant__c,Kunde__c,customfield__c FROM Order__c WHERE DatumZeit__c < :d';
oh sorry. the field in question is already included in my query (restaurant__c). However, for this field are different values ​​(a, b, c). and just because I need it for subsequent statements.
Phillip SouthernPhillip Southern
ok I'm sorry I dont understand what you need help with.......can you please clarify?  If you need help with your code in the execute method, please post it along with which part you need help with.
I have a custom field declared as a picklist.
I want to use the stored in the picklist values ​​in my batch script.
Is there a way to retrieve these values ​​from the picklist
Phillip SouthernPhillip Southern
Ahhh ok got it now...yes very possible.  What you want to do is a describe on the object to retrieve metadata and all the possible values.  here is a good reference from the dev blogs:

Its a bit dated (2008) but still holds true.  Instead of putting your values into a List<SelectOption> you just want them to store possibly in a set<string> or list<string>, etc to be used as needed.