Hey guys, In this post we are going to learn that how we can create a custom record search and delete record functionality in Salesforce lightning components.
In this example we will search Custom sObject records with an lightning input field.
Files we used in this post example:-
File Name | File Type | Description |
---|---|---|
studentInfoApp.app | Lightning Component Application | It is used for preview the component on browser. |
studentInfoCmp.cmp | Lightning Component | It is used for Search Inpur field and Record User InterfaceTable. |
studentInfoCmpController.js | JavaScript Controller File | It is used for search record and deleter record functionality. |
studentInfoCmpHelper.js | JavaScript Helper File | Helper function called in the Javascript controller on Init function. |
studentInfoCtrl.apxc | Apex Class Controller | It is used for For Search and delete record from database server |
Custom Object:- student_info__c Custom Object Fields:- student_first_name__c student_last_name__c student_phone__c
|
Custom Object and their fields | Custom object like database and custom fields are column of data table. |
Final Output
Other related post that would you like to learn in LWC
Other post that would you like to learn
Step 1:- Create Lightning Application : studentInfoApp.app
From Developer Console >> File >> New >> Lightning Application
studentInfoApp.app [Component Application File]
1 2 3 |
<aura:application extends="force:slds"> <c:studentInfoCmp /> </aura:application> |
Step 2:- Create Lightning Component : studentInfoCmp.cmp
From Developer Console >> File >> New >> Lightning Component
studentInfoCmp.cmp [Lightning Component File]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
<aura:component controller="studentInfoCtrl" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" > <aura:attribute name="studentInfoAc" type="student_info__c" default="{'sobjectType': 'student_info__c'}"/> <aura:handler name="init" value="{!this}" action="{!c.doInit}"/> <aura:attribute name="studentItrt" type="student_info__c[]"/> <div class="slds slds-p-horizontal--medium"> <div class="slds-large-size--3-of-12 slds-m-bottom--medium slds-p-around--small"> Search Student Name <ui:inputText aura:id="searchFld" value="" class="slds-input" keyup="{!c.searchRow}" updateOn="keyup" placeholder="Search Name..."/> </div> <div style="width:40%;"> <table class="slds-table slds-table--bordered"> <tr style="background-color:#eee;"> <th>First Name</th> <th>Last Name</th> <th>Phone</th> <th></th> </tr> <aura:iteration items="{!v.studentItrt}" var="studentItem" > <tr> <td>{!studentItem.student_first_name__c} </td> <td>{!studentItem.student_last_name__c}</td> <td>{!studentItem.student_phone__c}</td> <td><span><a style="color:#ff0000; font-weight:bold;" id="{!studentItem.Id}" onclick="{!c.deleteRow}" title="Delete">X</a></span></td> </tr> </aura:iteration> </table> </div> </div> </aura:component> |
Step 3:- Create Lightning Component : JavaScript Controller
From Developer Console >> File >> New >> Lightning Component >> JavaScript Controller
studentInfoCmpController.js [JavaScript Controller]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
({ doInit: function(component, event, helper) { helper.loadDetails(component, event); }, submitStudentInfo : function(component, event, helper) { var action = component.get('c.getStudent'); var postData = component.get('v.studentInfoAc'); console.log(':: postData ::: '+JSON.stringify(postData)); console.log(':: postData Name :: '+postData.student_first_name__c); action.setParams({"insertStudent": postData}); action.setCallback(this, function(response) { var state = response.getState(); if (state === "SUCCESS") { var stringItems = response.getReturnValue(); component.set("v.studentItrt",stringItems); component.set('v.studentInfoAc.student_first_name__c', ""); component.set('v.studentInfoAc.student_last_name__c', ""); component.set('v.studentInfoAc.student_phone__c', ""); } }); $A.enqueueAction(action); }, deleteRow : function(component, event, helper) { var thisObj = event.target.id; var action = component.get('c.deleteRowCtrl'); action.setParams({'deleteRowId':thisObj}); action.setCallback(this, function(response){ var state = response.getState(); if(state == 'SUCCESS'){ var getReturnRow = response.getReturnValue(); component.set('v.studentItrt', getReturnRow); //component.set('v.studentInfoAc', []); alert('Record deleted successfully'); } }); $A.enqueueAction(action); }, searchRow : function(component, event, helper) { var searchFld = component.find('searchFld').get("v.value"); var action = component.get('c.searchData'); action.setParams({'searchKey':searchFld}); action.setCallback(this, function(response){ var state = response.getState(); if(state == 'SUCCESS'){ var getReturnRow = response.getReturnValue(); component.set('v.studentItrt', getReturnRow); } }); $A.enqueueAction(action); }, }) |
Step 4:- Create Lightning Component : studentInfoCmpHelper.js
From Developer Console >> File >> New >> Lightning Component >> JavaScript Helper
studentInfoCmpHelper.js [JavaScript Helper File]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
({ loadDetails: function(component, event) { var studentItrt = component.get('v.studentItrt'); var action = component.get('c.loadStudentInfo'); action.setCallback(this, function(response){ var state = response.getState(); if(state == 'SUCCESS'){ var getResponse = response.getReturnValue(); component.set('v.studentItrt',getResponse); console.log('studentItrt::' + studentItrt); } }); $A.enqueueAction(action); }, }) |
Further post that would you like to learn
nice Article
Thanks For Sharing The Amazing content. I Will also share with my friends. Great Content thanks a lot.
Amazing Content
5 Internet Approval Site (Do Follow Backlinks)