• Aparna Jaiswar 7
  • NEWBIE
  • 30 Points
  • Member since 2021

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 2
    Replies
Hello, I have a object calles Mediatek/en

I tried to build a search component to find records in the List. When I inserted it and tried it I got an error message. How can I change the code so the error will not occure. I will give you the code sample and the screenshots.

User-added imageUser-added image
Error:

User-added image

Code:

<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId" access="global" >
 
    <!-- handlers-->
    <aura:handler name="init" value="{!this}" action="{!c.init}"/>
 
    <!-- attributes -->
    <aura:attribute name="showSearchResults" type="Boolean" default="false"/>
    <aura:attribute name="searchKey" type="String"/>
    <aura:attribute name="mediathekList" type="List" default="Mediathek[]"/>
    <aura:attribute name="mediathekColumns" type="List"/>
    
 
    <lightning:layout multipleRows="true">
        <lightning:layoutItem padding="around-small" size="9">
            <lightning:input name="searchKey" placeholder="Enter search key" value="{!v.searchKey}"/>
        </lightning:layoutItem>
        <lightning:layoutItem padding="around-small" size="3">
            <lightning:button variant="brand" label="Search" title="Search" onclick="{!c.search}" class="customButton"/>
        </lightning:layoutItem>
    </lightning:layout>
 
    <aura:if isTrue="{!v.showSearchResults}">
        <lightning:layout multipleRows="true">
            <lightning:layoutItem padding="around-small" size="12">
                Mediathek
                <lightning:datatable keyField="id"
                                     data="{!v.mediathekList}"
                                     columns="{!v.mediathekColumns}"
                                     hideCheckboxColumn="true"/>
            </lightning:layoutItem>
            
        </lightning:layout>
    </aura:if>
 
</aura:component>

Controller

({
    init: function (component, event, helper){
       component.set('v.mediathekColumns', [
            {label: 'Mediatheken Name', fieldName: 'Name', type: 'url', 
            typeAttributes: {label: { fieldName: 'Name' }, target: '_blank'}},
            
        ]);
        
    },
 
    search : function(component, event, helper) {
        helper.getSearchResultsFromApex(component, event, helper);
        component.set("v.showSearchResults",true);
    }
})

Helper

({
    getSearchResultsFromApex : function(component, event, helper){
     
        var action = component.get("c.getSearchResult");
        action.setParams({ searchKey : component.get("v.searchKey") });
     
        // Create a callback that is executed after
        // the server-side action returns
        action.setCallback(this, function(response) {
            var state = response.getState();
            if (state === "SUCCESS") {
 var result = response.getReturnValue();
  result.forEach(function(result){
                    result.Name = '/'+result.Id;
                      
                });
               
                // SOSL will always return the list in the order they were queried
                component.set("v.mediathekList",result[0]);
                  
                
            }
            else if (state === "INCOMPLETE") {
                // do something
            }
                else if (state === "ERROR") {
                    var errors = response.getError();
                    if (errors) {
                        if (errors[0] && errors[0].message) {
                            console.log("Error message: " +
                                        errors[0].message);
                        }
                    } else {
                        console.log("Unknown error");
                    }
                }
        });
        $A.enqueueAction(action);
    }
})

DESIGN

.THIS .customButton{
    margin-top: 19px;
}

.cSuchleiste_Media{
 height: 50px;
  background-color:#ffffff;
}
An Object Laptop is having fields Hard disk, Processor,RAM, and Capacity.
Requirement is to populate field Capacity as 'Low Capacity' when 
Hard disk < 40GB, Processor < 2 GHz and RAM < 1 GB  whenever record is Inserted/Edited. 
I am facing issues when I write trigger for edit case, I am not getting how to compare trigger.oldMap and trigger.newMap here to populate the Capacity field only when it is edited to subsequently meet the criteria. 
Please suggest solution using Trigger Only (as I want to do this by Trigger and not by Workflow Rule or Process Builder). 

Thanks
Hello, I have a object calles Mediatek/en

I tried to build a search component to find records in the List. When I inserted it and tried it I got an error message. How can I change the code so the error will not occure. I will give you the code sample and the screenshots.

User-added imageUser-added image
Error:

User-added image

Code:

<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId" access="global" >
 
    <!-- handlers-->
    <aura:handler name="init" value="{!this}" action="{!c.init}"/>
 
    <!-- attributes -->
    <aura:attribute name="showSearchResults" type="Boolean" default="false"/>
    <aura:attribute name="searchKey" type="String"/>
    <aura:attribute name="mediathekList" type="List" default="Mediathek[]"/>
    <aura:attribute name="mediathekColumns" type="List"/>
    
 
    <lightning:layout multipleRows="true">
        <lightning:layoutItem padding="around-small" size="9">
            <lightning:input name="searchKey" placeholder="Enter search key" value="{!v.searchKey}"/>
        </lightning:layoutItem>
        <lightning:layoutItem padding="around-small" size="3">
            <lightning:button variant="brand" label="Search" title="Search" onclick="{!c.search}" class="customButton"/>
        </lightning:layoutItem>
    </lightning:layout>
 
    <aura:if isTrue="{!v.showSearchResults}">
        <lightning:layout multipleRows="true">
            <lightning:layoutItem padding="around-small" size="12">
                Mediathek
                <lightning:datatable keyField="id"
                                     data="{!v.mediathekList}"
                                     columns="{!v.mediathekColumns}"
                                     hideCheckboxColumn="true"/>
            </lightning:layoutItem>
            
        </lightning:layout>
    </aura:if>
 
</aura:component>

Controller

({
    init: function (component, event, helper){
       component.set('v.mediathekColumns', [
            {label: 'Mediatheken Name', fieldName: 'Name', type: 'url', 
            typeAttributes: {label: { fieldName: 'Name' }, target: '_blank'}},
            
        ]);
        
    },
 
    search : function(component, event, helper) {
        helper.getSearchResultsFromApex(component, event, helper);
        component.set("v.showSearchResults",true);
    }
})

Helper

({
    getSearchResultsFromApex : function(component, event, helper){
     
        var action = component.get("c.getSearchResult");
        action.setParams({ searchKey : component.get("v.searchKey") });
     
        // Create a callback that is executed after
        // the server-side action returns
        action.setCallback(this, function(response) {
            var state = response.getState();
            if (state === "SUCCESS") {
 var result = response.getReturnValue();
  result.forEach(function(result){
                    result.Name = '/'+result.Id;
                      
                });
               
                // SOSL will always return the list in the order they were queried
                component.set("v.mediathekList",result[0]);
                  
                
            }
            else if (state === "INCOMPLETE") {
                // do something
            }
                else if (state === "ERROR") {
                    var errors = response.getError();
                    if (errors) {
                        if (errors[0] && errors[0].message) {
                            console.log("Error message: " +
                                        errors[0].message);
                        }
                    } else {
                        console.log("Unknown error");
                    }
                }
        });
        $A.enqueueAction(action);
    }
})

DESIGN

.THIS .customButton{
    margin-top: 19px;
}

.cSuchleiste_Media{
 height: 50px;
  background-color:#ffffff;
}