4

I want to get label of picklist from soql and use it in my apex code to do some logic. For example following code gives me error

Compile failure on line 7, column 18: Invalid field labelType for SObject FieldSet__c

In below code how do I get the label for picklist in my apex code.Thanks for your help and time.

List<FieldSet__c> fieldSets = [SELECT toLabel(Type__c) labelType,Type__c
FROM FieldSet__c];

for (FieldSet__c fieldSet : fieldSets) 
{
    System.debug(fieldSet.labelType);
}
6

You can access it by sobject get method like: fieldSet.get('labelType') and you can select both label and picklistvalue in single query.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.