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
Jonathan Wolff 7Jonathan Wolff 7 

Code adjustments to get lightning:select options from custom object picklist

Hello, I have 3 lightning:select regions in my component. They display the options from picklists in my custom object Mediathek__c. Could you tell me how to get the values from the picklists? The picklist fields are Typ__c, Zielgruppe__c and Thema__c.

My code for the component is the following:

Component
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId" access="global" controller="MediathekSearchController">
    
    <!-- handlers-->
    <aura:handler name="init" value="{!this}" action="{!c.init}"/>
    <!-- <aura:handler name="change" value="{!v.searchKey}" action="{!c.valueChangeValidation}"/> -->
    
    <!-- attributes -->
    <aura:attribute name="showSearchResults" type="Boolean" default="false"/>
    <aura:attribute name="searchKey" type="String" default=""/>
    <aura:attribute name="mediathekList" type="List" default="Mediathek[]"/>
    <aura:attribute name="mediathekColumns" type="List"/>
    <aura:attribute name="accL" type="List"/> 
    <aura:attribute name="TypValue" type="String" default="Alle"/>
    <aura:attribute name="ZielgruppeValue" type="String" default="Alle"/>
    <aura:attribute name="ThemaValue" type="String" default="Alle"/>
    <aura:attribute name="tooltip" type="boolean" default="false" />
       
    <!--  <div class= "slds-box slds-p-top_none slds-p-bottom_none slds-p-right_none"> -->
    <div class= "slds-box slds-p-left_medium slds-p-bottom_medium">
        <div class="slds-grid slds-wrap" >
            <div class="slds-size_12-of-12 ">
                <lightning:layout multipleRows="true">
                    
                    <lightning:layoutItem  size="7">
                        <lightning:input class="Eingabe" aura:id="inputField" name="searchKey" placeholder="Bitte geben Sie mindestens 2 Buchstaben ein, um zu suchen" value="{!v.searchKey}"  onkeyup="{!c.search}" messageWhenBadInput="Es müssen mindestens 2 Zeichen eingegeben werden"/>
                    </lightning:layoutItem>
                    <lightning:layoutItem  size="1"/>
                    <lightning:layoutItem  size="1">
                        <lightning:button  variant="brand" label="Suchen" title="Search" onclick="{!c.search}" class="customButton1" />
                    </lightning:layoutItem>
                    <lightning:layoutItem  size="1">
                        <lightning:button  variant="brand" label="Reset" title="Reset" onclick="{!c.reset}" class="customButton2" />
                    </lightning:layoutItem>
                    <lightning:layoutItem  size="2"/>
                    
                    <lightning:layoutItem  size="3">
                        <lightning:select name="mediathekType" label="Select Mediathek Type" aura:id="acId">
                        <aura:iteration items="{!v.accL}" var="a" > 
					<option value="{!a.Id}" text="{!a.Id}"/> 

					</aura:iteration> 
						</lightning:select> 
                       <!-- <lightning:select class="TypValue" aura:id="TypValue" name="Typ" label="Typ" required="false" value="{!v.TypValue}">
                            
                            <option value="Alle">Alle</option>
                            <option value="Formular">Formular</option>
                            <option value="Merkblatt">Merkblatt</option>
                            <option value="Flyer">Flyer</option>
                            <option value="Infobroschüre">Infobroschüre</option>
                        </lightning:select> -->
                    </lightning:layoutItem>
                    
                    <lightning:layoutItem  size="1"/>
                    <lightning:layoutItem  size="3">
                        
                        <lightning:select class="ThemaValue" aura:id="ThemaValue" name="Thema" label="Thema" required="false" value="{!v.ThemaValue}">
                            
                            <option value="Alle">Alle</option>
                            <option value="Altersvorsorge">Altersvorsorge</option>          
                            <option value="AOK">AOK</option>
                            <option value="Beratungstag">Beratungstag</option>
                            <option value="Berufsunfähigkeit">Berufsunfähigkeit</option>
                            <option value="Berufsunfähigkeit privat">Berufsunfähigkeit privat</option>
                            <option value="bKV">bKV</option>
                            <option value="BRSG">BRSG</option>
                            <option value="Direktversicherung">Direktversicherung</option>
                            <option value="Direktversicherung, ergänzende Berufsunfähigkeit, Berufsunfähigkeit">Direktversicherung, ergänzende Berufsunfähigkeit, Berufsunfähigkeit</option>
                            <option value="Direktversicherung, Pensionsfonds">Direktversicherung, Pensionsfonds</option>
                            <option value="Direktversicherung, Pensionskasse">Direktversicherung, Pensionskasse</option>
                            <option value="Direktversicherung, Pensionskasse, Pensionsfonds">Direktversicherung, Pensionskasse, Pensionsfonds</option>
                            <option value="englisches Material">englisches Material</option>
                            <option value="FID FIR">FID FIR</option>
                            <option value="Firmenversicherung (Gruppenvertrag)">Firmenversicherung (Gruppenvertrag)</option>
                            <option value="Kundencall">Kundencall</option>
                            <option value="Lebensversicherung privat">Lebensversicherung privat</option>
                            <option value="Pensionsfonds">Pensionsfonds</option>
                            <option value="Pensionskasse">Pensionskasse</option>
                            <option value="Pensionszusage">Pensionszusage</option>
                            <option value="privat">privat</option>
                            <option value="PrivatRente, Schatzbrief Perspektive">PrivatRente, Schatzbrief Perspektive</option>
                            <option value="Produktinfo">Produktinfo</option>
                            <option value="rechtliche Unterlage">rechtliche Unterlage</option>
                            <option value="Riester">Riester</option>
                            <option value="Rückdeckungsversicherung FIR">Rückdeckungsversicherung FIR</option>
                            <option value="Unterstützungskasse">Unterstützungskasse</option>
                            <option value="Zeitwertkonto">Zeitwertkonto</option>
                            <option value="Zusatzbausteine">Zusatzbausteine</option>
                            
                        </lightning:select>
                        
                    </lightning:layoutItem>
                    <lightning:layoutItem  size="1"/>
                    
                    <lightning:layoutItem  size="3">
                        <lightning:select class="ZielgruppeValue text-left" aura:id="ZielgruppeValue" name="Zielgruppe" label="Zielgruppe" required="false" value="{!v.ZielgruppeValue}">
                            
                            <option value="Alle">Alle</option>          
                            <option value="Arbeitgeber">Arbeitgeber</option>
                            <option value="Arbeitnehmer">Arbeitnehmer</option>
                            <option value="Berater">Berater</option>
                            <option value="Verband">Verband</option>
                            <option value="Arbeitgeber/Arbeitnehmer">Arbeitgeber/Arbeitnehmer</option>
                            <option value="Azubi">Azubi</option>
                            <option value="IGM">IGM</option>
                        </lightning:select>
                    </lightning:layoutItem>
                    
                </lightning:layout>
                
                
            </div>
        </div>
        <div class="Ausgabe" style="margin-right:400px">
            <aura:if isTrue="{!AND(v.showSearchResults, v.searchKey.length>1)}" >
                
                
                <!--      <lightning:layout multipleRows="true">
                <lightning:layoutItem padding="around-large" size="12" >
                    <lightning:datatable keyField="id"
                                         data="{!v.mediathekList}"
                                         columns="{!v.mediathekColumns}"
                                         hideCheckboxColumn="true"/>
                    
                    
        
                </lightning:layoutItem>
            </lightning:layout>  -->
                
                <table class="slds-table slds-table--bordered slds-table--striped " style="width: 880px">
                    <thead>
                        <tr>
                            <th scope="col"><span class="slds-truncate">Suchergebnisse</span></th>
                            <th scope="col"><span class="slds-truncate"></span></th>
                        </tr>
                    </thead>
                    <tbody style="background-color:#F8F8F8">
                        <aura:iteration items="{!v.mediathekList}" var="media">
                            <tr style="background-color:#F8F8F8">                             
                                <td valign="top" style="background-color:#F8F8F8" > 
                                    <a href="{!'/'+media.Mediathek_ID_Long__c}"><b>{!media.Bezeichnung__c}</b></a><br/>                     
                                    Typ: <b>{!media.Typ__c}</b><br/>
                                    Zielgruppe: <b>{!media.Zielgruppe__c}</b><br/>
                                    Umfang: <b>{!media.Umfang__c}</b>                                 
                                </td>                              
                                <aura:if isTrue="{!not(empty(media.ContentVersionId__c))}" > 
                                    
                                    <td style="background-color:#F8F8F8;"><img style="height:170px; border: 1px solid #555;" 
                                                                               
                                                                               src="{!'/sfc/servlet.shepherd/version/renditionDownload?rendition=THUMB720BY480&amp;versionId=' + media.ContentVersionId__c}" />
                                        
                                    </td>
                                </aura:if>
                                <aura:if isTrue="{!empty(media.ContentVersionId__c)}" > 
                                    
                                    <td style="background-color:#F8F8F8;">
                                        
                                    </td>
                                </aura:if>
                                
                            </tr> 
                        </aura:iteration>
                    </tbody>
                </table>
            </aura:if>
        </div>
    </div>  
</aura:component>

Controller
({
  /*  init: function (component, event, helper){
       component.set('v.mediathekColumns', [
           {label: 'Bezeichnung', fieldName: 'Bezeichnung_Search__c', type: 'url' , fixedWidth: 395, 
             typeAttributes: {label: { fieldName: 'Bezeichnung__c' }, target: '_blank'}
            },
           {label: 'Typ', fieldName: 'Typ__c', type: 'text',  fixedWidth: 116,
            },
           {label: 'Zielgruppe', fieldName: 'Zielgruppe__c', type: 'text', fixedWidth: 116,
            },
           {label: 'Umfang', fieldName: 'Umfang__c', type: 'text', fixedWidth: 112,
           },
            {label: 'Preview', fieldName: 'Bild_Preview__c', type: 'image',  fixedWidth: 300,
            },
           
         
          ]); 
             var action = component.get("c.getSearchResult");
       
       
        action.setCallback(this, function(response){
            var state = response.getState();
            if (state === "SUCCESS") {
                var records =response.getReturnValue();
                records.forEach(function(record){
                    
           			record.BEZ = record.Bezeichnung__c;
                });
                component.set("v.mediathekList", records);
            }
        });
        $A.enqueueAction(action);
    }, */

	        
    search : function(component, event, helper) {
        helper.getSearchResultsFromApex(component, event, helper);
      
        component.set("v.showSearchResults",true);
        
    },
    
     reset : function(component, event, helper) {
        helper.getSearchResultsFromApex(component, event, helper);
        component.set("v.showSearchResults",false);
        component.set("v.searchKey",null);
        component.set("v.TypValue",'Alle');
        component.set("v.ZielgruppeValue",'Alle');
        component.set("v.ThemaValue",'Alle');
    }
})


({
    init: function (component, event, helper){
       component.set('v.mediathekColumns', [
          
            {label: 'Bezeichnung', fieldName: 'Bezeichnung_Search__c', type: 'url' , fixedWidth: 395, 
             typeAttributes: {label: { fieldName: 'Bezeichnung__c' }, target: '_blank'}
            },
           {label: 'Thema', fieldName: 'Thema__c', type: 'text', fixedWidth: 112,
           },
           {label: 'Typ', fieldName: 'Typ__c', type: 'text',  fixedWidth: 116,
            },
           {label: 'Zielgruppe', fieldName: 'Zielgruppe__c', type: 'text', fixedWidth: 116,
            },
           {label: 'Umfang', fieldName: 'Umfang__c', type: 'text', fixedWidth: 112,
           },
           
         
          ]);
           
        	
           
             var action = component.get("c.getSearchResult");
       	
        action.setCallback(this, function(response){
            var state = response.getState();
            if (state === "SUCCESS") {
                var records =response.getReturnValue();
           	
			
                records.forEach(function(record){
                    
           			record.BEZ = record.Bezeichnung__c;
                });
                component.set("v.mediathekList", records);
            }
        });
        $A.enqueueAction(action);
    },


        
    search : function(component, event, helper) {
        helper.getSearchResultsFromApex(component, event, helper);
        component.set("v.showSearchResults",true);
    },
    
   
  
})

Apex
public with sharing class MediathekSearchController {
    

    @AuraEnabled(cacheable=true)
    public static List<List<sObject>> getSearchResult(String searchKey, String TypValue, String ZielgruppeValue, String ThemaValue){
        String findStr = '*'+searchKey+'*';
        
        Boolean isEmptySearch = String.isEmpty(searchKey);
        
        
        
        system.debug('searchKey ' + searchKey);
        system.debug('findStr ' + findStr);
        system.debug('KategorieValue' + TypValue);   
        system.debug('ZielgruppeValue' + ZielgruppeValue);
        system.debug('ThemaValue' + ThemaValue);
        
        
        List<List<sObject>> searchResult;
       
             if(ThemaValue == 'Alle' && ZielgruppeValue == 'Alle' && TypValue == 'Alle'){
                						searchResult = [FIND :findStr IN ALL FIELDS 
                                        RETURNING Mediathek__c (Id, Mediathek_ID_Long__c,  Thema__c, ContentDocumentID__c, ContentVersionId__c, Thumbnail_Image__c,Thumbnail_Preview2__c, Name, Bezeichnung__c, Typ__c, Zielgruppe__c, Umfang__c, Bezeichnung_Link__c, Bezeichnung_Search__c Where Inaktiv__c=false)];
             } 
        
    		else if(ThemaValue == 'Alle' && ZielgruppeValue == 'Alle' && TypValue != 'Alle'){ 
                        searchResult = [FIND :findStr IN ALL FIELDS 
                                        RETURNING Mediathek__c (Id,  Thema__c, Mediathek_ID_Long__c, Name, Bezeichnung__c, ContentDocumentID__c, Thumbnail_Image__c, Typ__c, Zielgruppe__c, Umfang__c, Bezeichnung_Link__c, Bezeichnung_Search__c
                                                                WHERE Typ__c=:TypValue AND Inaktiv__c=false)];
             }
        
        	else if(ThemaValue == 'Alle' && ZielgruppeValue != 'Alle' && TypValue == 'Alle'){ 
                        searchResult = [FIND :findStr IN ALL FIELDS 
                                        RETURNING Mediathek__c (Id,  Thema__c, Mediathek_ID_Long__c, Name, Bezeichnung__c, Typ__c, ContentDocumentID__c, Thumbnail_Image__c, Zielgruppe__c, Umfang__c, Bezeichnung_Link__c, Bezeichnung_Search__c
                                                                WHERE Zielgruppe__c=:ZielgruppeValue AND Inaktiv__c=false)];
             }
        
        	else if(ThemaValue != 'Alle' && ZielgruppeValue == 'Alle' && TypValue == 'Alle'){ 
                        searchResult = [FIND :findStr IN ALL FIELDS 
                                        RETURNING Mediathek__c (Id,  Thema__c, Name, Mediathek_ID_Long__c, Bezeichnung__c, Typ__c, ContentDocumentID__c, Zielgruppe__c, Umfang__c, Bezeichnung_Link__c, Bezeichnung_Search__c
                                                                WHERE Thema__c=:ThemaValue AND Inaktiv__c=false)];
             }
        
        	else if(ThemaValue == 'Alle' && ZielgruppeValue != 'Alle' && TypValue != 'Alle'){ 
                        searchResult = [FIND :findStr IN ALL FIELDS 
                                        RETURNING Mediathek__c (Id,  Thema__c, Name, Mediathek_ID_Long__c, Bezeichnung__c, Typ__c, ContentDocumentID__c, Zielgruppe__c, Umfang__c, Bezeichnung_Link__c, Bezeichnung_Search__c
                                                                WHERE Typ__c=:TypValue AND Zielgruppe__c=:ZielgruppeValue AND Inaktiv__c=false)];
             }
                    
                    
             else if(ThemaValue != 'Alle' && ZielgruppeValue != 'Alle' && TypValue == 'Alle'){ 
                        searchResult = [FIND :findStr IN ALL FIELDS 
                                        RETURNING Mediathek__c (Id,  Thema__c, Name, Mediathek_ID_Long__c, Bezeichnung__c, Typ__c, ContentDocumentID__c, Zielgruppe__c, Umfang__c, Bezeichnung_Link__c, Bezeichnung_Search__c
                                                                WHERE Thema__c=:ThemaValue AND Zielgruppe__c=:ZielgruppeValue AND Inaktiv__c=false)];
             }          
              else if(ThemaValue != 'Alle' && ZielgruppeValue == 'Alle' && TypValue != 'Alle'){ 
                        searchResult = [FIND :findStr IN ALL FIELDS 
                                        RETURNING Mediathek__c (Id,  Thema__c, Name, Mediathek_ID_Long__c, Bezeichnung__c, ContentDocumentID__c, Typ__c, Zielgruppe__c, Umfang__c, Bezeichnung_Link__c, Bezeichnung_Search__c
                                                                WHERE Thema__c=:ThemaValue AND Typ__c=:TypValue AND Inaktiv__c=false)];
                                   
                    }
        
              else if(ThemaValue != 'Alle' && ZielgruppeValue != 'Alle' && TypValue != 'Alle'){ 
                        searchResult = [FIND :findStr IN ALL FIELDS 
                                        RETURNING Mediathek__c (Id,  Thema__c, Mediathek_ID_Long__c, Name, Bezeichnung__c, ContentDocumentID__c, Typ__c, Zielgruppe__c, Umfang__c, Bezeichnung_Link__c, Bezeichnung_Search__c
                                                                WHERE Thema__c=:ThemaValue AND Typ__c=:TypValue AND Zielgruppe__c=:ZielgruppeValue AND Inaktiv__c=false)];
                    
                } 
            
              
       
            return searchResult;
        }
    
    
    
    
    }

​​​​​​​
SubratSubrat (Salesforce Developers) 
.