Skip to main content
added 103 characters in body
Source Link
Keith C
  • 137.3k
  • 29
  • 218
  • 458

One way to return an array of objects where the object fields have the keys of "value" and "label" as required by your component is:

@AuraEnabled
public static List<Map<String, String>> getRecordTypes() {

    System.debug('getRecordTypes starting...');

    List<Map<String, String>> items = new List<Map<String, String>>();
    for (RecordType rt : [
            SELECT id, name
            FROM RecordType
            WHERE SobjectType = 'IP__c'
            ]) {
        items.add(new Map<String, String>{'value' => rt.Id, 'label' => rt.Name});
    }
    return items;
}

Or if you are doing a lot of this, you can create your own class as described in Why is SelectOption not supported by JSON class?.

PS

This markup to match this is:

<option text="{!item.label}" value="{!item.value}"/>

One way to return an array of objects where the object fields have the keys of "value" and "label" as required by your component is:

@AuraEnabled
public static List<Map<String, String>> getRecordTypes() {

    System.debug('getRecordTypes starting...');

    List<Map<String, String>> items = new List<Map<String, String>>();
    for (RecordType rt : [
            SELECT id, name
            FROM RecordType
            WHERE SobjectType = 'IP__c'
            ]) {
        items.add(new Map<String, String>{'value' => rt.Id, 'label' => rt.Name});
    }
    return items;
}

Or if you are doing a lot of this, you can create your own class as described in Why is SelectOption not supported by JSON class?.

One way to return an array of objects where the object fields have the keys of "value" and "label" as required by your component is:

@AuraEnabled
public static List<Map<String, String>> getRecordTypes() {

    System.debug('getRecordTypes starting...');

    List<Map<String, String>> items = new List<Map<String, String>>();
    for (RecordType rt : [
            SELECT id, name
            FROM RecordType
            WHERE SobjectType = 'IP__c'
            ]) {
        items.add(new Map<String, String>{'value' => rt.Id, 'label' => rt.Name});
    }
    return items;
}

Or if you are doing a lot of this, you can create your own class as described in Why is SelectOption not supported by JSON class?.

PS

This markup to match this is:

<option text="{!item.label}" value="{!item.value}"/>
Source Link
Keith C
  • 137.3k
  • 29
  • 218
  • 458

One way to return an array of objects where the object fields have the keys of "value" and "label" as required by your component is:

@AuraEnabled
public static List<Map<String, String>> getRecordTypes() {

    System.debug('getRecordTypes starting...');

    List<Map<String, String>> items = new List<Map<String, String>>();
    for (RecordType rt : [
            SELECT id, name
            FROM RecordType
            WHERE SobjectType = 'IP__c'
            ]) {
        items.add(new Map<String, String>{'value' => rt.Id, 'label' => rt.Name});
    }
    return items;
}

Or if you are doing a lot of this, you can create your own class as described in Why is SelectOption not supported by JSON class?.