Posts

Showing posts from May, 2017

Lightning Component for Hours of Operation

Image
Often we have a business use case from sales users to be able to capture Hours of Operation from their customers. Here we are going to build a reusable Lightning Component that we can place on any Object (Standard or Custom) detail page . Below are Code blocks that assembles to form our Lightning Component! Controller Class: Note** Just make sure to create a custom field with Api "Hours__c" on any sObject that you want to place this Component and update Hours. public class HoursOfOperation { @AuraEnabled public static String getUpdtHrs(String sObjName, String sObjId, String hrs) { try { //query string to pull specific record to update hours String qry = 'Select Id, Name, Hours__c From ' + sObjName + ' Where Id=\'' + sObjId +'\'' + ' Limit 1'; List<sObject> lstRcds = Database.query(qry); //check if above query returns atleast one record if (lstRcd...

Lightning Component to display dynamic sObject data

Image
Here in this blog, we are going to build a Lightning Component to display some standard field's data (Like Id, Name, CreatedByName, etc.,) for any given sObject that we are going to dynamically retrieve based upon record detail page on which our Lightning Component is placed! First we create a Class with a method to fetch records using sObject Name..... Below is the Controller Class to return sObject rows: 1: public class DynamicSObjectResults { 2: @AuraEnabled 3: public static List<Object> getObjRslts(String objName) { 4: String qry = 'Select Id, Name, CreatedBy.Name From ' + objName + ' Limit 6'; 5: List<Object> lstRcds = Database.query(qry); 6: return lstRcds; 7: } 8: } Now we create our Component and Component Controller Below is the Component Code: 1: <aura:component controller="DynamicSObjectResults" implements="force:hasRecordId,force:hasSObjectName,flexipage:availableForAl...

Aura Supported Attributes- Part 2

Image
We looked at some basic attribute types in my last post . Now lets look at other attribute types that are available for Lightning Components development Object Types: This attribute type is declared as a type 'Object' and used for passing any type of event parameter's like Array of String, Array of Integer, etc.,           Object Type Attribute: <aura:attribute name="objTypeAttr" type="Object" default="['Test1', 'Test2']" /> Standard and Custom Object Types: This extends above attribute types in order to be able to use both Standard and Custom Objects           Standard Object Attribute: <aura:attribute name="standObj" type="Account" />           Custom Object Attribute: <aura:attribute name="cstmObj" type="Expense__c" /> Collection Types: We have Four collection attribute types for use [Type[], List, Set, and Map] Custom Apex Class Type...

Aura Supported Attributes- Part 1

Image
Aura Attributes play an important role in holding Data when working with Lighting Component development and here I am going to play with some Aura Attributes that support different Types Lightning Components Developer Guide  has in depth explanation about these attributes Basic declaration of an aura attribute is ' <aura:attribute name="Test" type="String"/>'  here both 'name' and 'type' are required parameter's for an attribute with optional parameter's as 'access', 'default', 'required', and 'description' For any given attribute we can declare its Type as one of the following a. Basic Types b. Object Types c. Standard and Custom Object Types d. Collection Types e. Custom Apex Class Types f. Framework-Specific Types Lets put some Basic attribute types into action using a simple Lightning Component..... From Developer Console navigate to File-->New-->Lightning Component and ...

Replace Javascript custom button (To display VF Page) with New Custom Visualforce Action for Lightning

Image
Hi All, This is my first blog post and I plan to start this journey by writing a post on one common issue faced with Javascript custom button while trying to migrate from Class to Lightning. I know there are many other resources available online, in fact Lightning Component Developer Guide itself is a great resource and my attempt here is just to post my experience! Here we are going to create a new "Action" Button that will display content from our existing VF Page and this will replace our use case of using JavaScript Custom Button in Classic VF Page: <apex:page standardController="Expense__c" extensions="Expenses_VF_1Contlr"> <apex:form >     <apex:pageBlock >         <apex:pageblockButtons location="top">             <apex:commandButton value="Save" action="{!updtRcd}"/>         </apex:pageblockButtons>         <apex:pageMessages ...