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
Anuj kumar raiAnuj kumar rai 

Can a wired property that is getting a list of strings from apex method be treated as an array directly?

This is my apex method that is returning a list:
@AuraEnabled(cacheable=true)
    public static List<String> getTypePicklistValuesMethod(){
        List<String> pickListValuesList= new List<String>();
         Schema.DescribeFieldResult fieldResult = Task.Type.getDescribe();
         List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
         for( Schema.PicklistEntry pickListVal : ple){
             pickListValuesList.add(pickListVal.getLabel());
         }    
         return pickListValuesList;
    }

and this is my JS file:
import { LightningElement, wire} from 'lwc';
import picklistValues from '@salesforce/apex/TaskCreator.getTypePicklistValuesMethod';

export default class ListToMapPractice extends LightningElement
{
    @wire(picklistValues)
    typeValues;
}

So can this "typeValues" be directly used as an array or is there something more to it that i don't know yet.
Shivdeep KumarShivdeep Kumar
Hi Anuj,
Yes, you can use the wire property directly on the HTML. but as I can see that you are quering the picklist values and wanted to show on the HTML. 
If yes, please use the below code-
// HTML
<lightning-card title="SObject selection">
                <div class="slds-p-horizontal_small">              
                    <lightning-combobox class="slds-align-middle slds-text-align_center"
                           value={selectedValue}
                            placeholder="--None--"
                            options={picklistOptions}
                            required = true
                    ></lightning-combobox>           
                </div>
            </lightning-card>

//JS
picklistOptions;
    selectedValue;
@wire(picklistValues)
typeValues({error,data}){
if(data){
this.picklistOptions = Object.entries(data).map(([value,label]) => ({ value, label }));
}else if(error){

}

//Apex
@AuraEnabled(cacheable=true)
    public static Map<String, String> picklistValues(){
        Map<String, String> picklistValuesMap = new Map<String, String>();
        
        Schema.SObjectType objSobjectType = Schema.getGlobalDescribe().get('task') ;
        Schema.DescribeSObjectResult objDescribeSobject = objSobjectType.getDescribe() ;
        Map<String,Schema.SObjectField> fields = objDescribeSobject.fields.getMap() ;
        Schema.DescribeFieldResult fieldResult = fields.get('Type').getDescribe();
        List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
        for( Schema.PicklistEntry pickListVal : ple){
            picklistValuesMap.put(pickListVal.getLabel(),pickListVal.getValue());
        }
        return sObjectOptions;
    }
Please let me know if this helps!

Thanks,
Shivdeep Kumar