Posts

Showing posts from June, 2018

Lightning:recordForm - Lightning Data Service

Image
Lightning:recordForm is a very powerful component for editing, viewing and adding a record in lightning and combines both lightning:recordEditForm and lightning:recordViewForm. Here is an example lightning component for lightning:recordForm. Lightning Component:- <aura:component implements="flexipage:availableForRecordHome,force:hasSObjectName,force:hasRecordId" access="global" >     <aura:attribute name="fieldsList" type="String[]" default="['Id', 'Name', 'BillingAddress', 'Phone' , 'Type']"/>     <div class="THIS">                <lightning:recordForm                               recordId="{!v.recordId}"                               objectApiName="{!v.sObjectName}"                               fields="{!v.fieldsList}"                               columns="2"                               mode="View&qu

Custom Lookup Lightning Component

Image
Lookup Relationship: A Lookup Relationship creates a field that allows users to click a Lookup Icon and select another record from a popup window. In visual force pages, we create a lookup field simple using  " apex:inputField" component. But, in lightning components, we can not create a lookup field simply using any component like above. So, here we can find the solution for this please find the Lightning components below to create a lookup field. Apex Controller: public class InputLookup {     @AuraEnabled     public static SObject loadDefault(String s, String sObjectType) {         try {             String query = 'SELECT Id, Name FROM {1} WHERE Id={0}';             return Database.query(String.format(query, new List<String> { '\''+s+'\'', sObjectType }));         } catch (Exception e) {                }          return null;     }     @AuraEnabled     public static List<SObject> searchLookup(String s, St

Fixed Header For DataTable

Lightning Component: <aura:component implements="force:appHostable" >     <div class="slds-table--header-fixed_container" style="height:450px;">         <div class="slds-scrollable_y" style="height:100%;">             <table class="slds-table slds-table_bordered slds-table--header-fixed">                 <thead>                     <tr class="slds-text-title_caps">                         <th scope="col">                             <div class="slds-truncate slds-cell-fixed" title="Opportunity Name">Opportunity Name</div>                         </th>                         <th scope="col">                             <div class="slds-truncate slds-cell-fixed" title="Account Name">Account Name</div>                         </th>                         <th

Lightning Component Using RecordEdit and RecordView

Lightning componet: <aura:component implements="force:appHostable,force:lightningQuickAction,force:hasRecordId,flexipage:availableForRecordHome">     <aura:attribute name="flag" type="boolean" default="true" />     <aura:attribute name="recordId" type="Id"/>     <article class="slds-card">         <aura:if isTrue="{!v.flag}">             <force:recordView recordId="{!v.recordId}" type="FULL"/>             <aura:set attribute="else">                 <force:recordEdit aura:id="edit" recordId="{!v.recordId}"/>             </aura:set>         </aura:if>         <button class="slds-button slds-button_neutral">Cancel</button>         <aura:if isTrue="{!!v.flag}">             <ui:button label="Save" press="{!c.save}"/>        

Lightning Component For Custom RecordType Selection

Image
In this post, I am going to create a Lightning Component which is a replica of RecordType selector in Lightning. Apex Controller: Here, we are getting List of RecordTpes from Account Object. public class RecordTypeSelectorController {       @AuraEnabled     public static List<RecordType> getListOfRecordType(){         String query = 'SELECT Id,Name FROM RecordType WHERE SobjectType =\''+'Account'+'\' ';         List<RecordType> rtNames = new List<RecordType>();         Schema.SObjectType  objType = Account.SObjectType;              for(RecordTypeInfo rt : objType.getDescribe().getRecordTypeInfos()){             System.debug('rt.getName()'+rt.getName());             rtNames.add(new RecordType(Id = rt.getRecordTypeId(),Name = rt.getName()));             System.debug('rtNames'+rtNames);         }          return rtNames;      } } Lightning Component: <aura:component implements="force:appHost