Lightning Data Service (LDS) is to serve as the data layer for Lightning. It is similar like Standard Controllers in Visualforce Page.
Advantages of Lightning Data Service:
Lightning Data Service allows to load, create, edit, or delete a record without requiring Apex code and SOQL query.
Lightning Data Service handles sharing rules and field-level security.
Records loaded in Lightning Data Service are cashed and shared across all components.
When one component updates a record, the other component using it are notified.
Lightning Data Service supports offline in Salesforce1.
In below example I’m creating Lead object record using Lightning Data Service. By using the new base lightning component lightning:recordEditForm, we can create and edit records, without custom Javascript and Apex code.
({
handleOnSuccess : function(component, event, helper) {
var toastEvent = $A.get("e.force:showToast");
toastEvent.setParams({
"title": "Success!",
"message": "The record has been created successfully.",
"type": "success",
"mode": "pester"
});
toastEvent.fire();
$A.get("e.force:refreshView").fire();
}
})
We can use lightning:dualListbox component to show multi select picklist field values. lightning:dualListbox component represents two side-by-side list boxes. Select one or more options in the list on the left. Move selected options to the list on the right. The order of the selected options is maintained and we can reorder options.
Here in below example I’m using a Custom object “Book”, and the multi select picklist field “Genre” of “Book” object. Apex Class:
public class SampleAuraController {
@AuraEnabled
public static List <String> getPiklistValues() {
List<String> plValues = new List<String>();
//Get the object type from object name. Here I've used custom object Book.
Schema.SObjectType objType = Schema.getGlobalDescribe().get('Book__c');
//Describe the sObject using its object type.
Schema.DescribeSObjectResult objDescribe = objType.getDescribe();
//Get the specific field information from field name. Here I've used custom field Genre__c of Book object.
Schema.DescribeFieldResult objFieldInfo = objDescribe.fields.getMap().get('Genre__c').getDescribe();
//Get the picklist field values.
List<Schema.PicklistEntry> picklistvalues = objFieldInfo.getPicklistValues();
//Add the picklist values to list.
for(Schema.PicklistEntry plv: picklistvalues) {
plValues.add(plv.getValue());
}
plValues.sort();
return plValues;
}
}