Posts

Lightning Component With Bitly Integration

Image
About Bitly Bitly is a URL shortening service and a link management platform. The company Bitly, Inc. was established in 2008. It is privately held and based in New York City. Bitly shortens 600 million links per month, for use in social networking, SMS, and email Step 1. Sign-up for Bitly (FREE) For Integration, we have to register for Bitly Account. Step 2. Authorization with Salesoforce For Authorization in Salesoforce. I'm using Named Credentials. because Its simplest and secure way to use. Setup | Security Controls | Named Credentials. Create a new Named Credential to store your Bitly username/password. Step 4. Create BitlyIntegration Apex Classes public class BitlyIntegration { private String accessToken; public BitlyIntegration() { this.accessToken = getAccessToken(); } //Method for create shorten URL from Bitly public String createShortenURL(String url) { HttpRequest req = new HttpRequest(); //'c...

Lightning Validation with Custom Message : Aura vs LWC

Image
Lightning Validation : Aura Component LightningValidation.cmp (Component) Fill Information LightningValidation.js (JS Controller ) ({ handleValidation : function(cmp) { var allValid = cmp.find('validfield').reduce(function (validSoFar, inputCmp) { inputCmp.reportValidity(); return validSoFar && inputCmp.checkValidity(); }, true); if (allValid) { //Submit information on Server } else { alert('Please fill required and update all invalid form entries'); } }, handleCustomValidation : function(cmp,event) { var inputValue = event.getSource().get("v.value"); // is input valid text? if (inputValue.indexOf('@')>=0) { inputCmp.setCustomValidity("Please Don't include '@' in name"); } else { input...

Lightning Picklist/Select : Aura vs LWC

Image
Lightning Picklist/Select : Aura Component PickListOptionsController(Apex Controller ) public class PickListOptionsController { @AuraEnabled public static List getPickListOptionList(String objectName, String picklistFieldName){ List picklistOptionList = new List (); Schema.SObjectType convertToObj = Schema.getGlobalDescribe().get(objectName); Schema.DescribeSObjectResult res = convertToObj.getDescribe(); Schema.DescribeFieldResult fieldResult = res.fields.getMap().get(picklistFieldName).getDescribe(); List ple = fieldResult.getPicklistValues(); for( Schema.PicklistEntry pickListVal : ple){ picklistOptionList.add(pickListVal.getLabel()); } return picklistOptionList; } } PickListOptionsComponent.cmp (Component) Choose one... ...

Lightning Input Type File : Aura v/s LWC

Image
Aura Component Aura Component : HTML Aura Component : Controller JS ({ onFileUploaded:function(component,event,helper){ helper.show(component,event); var files = component.get("v.fileToBeUploaded"); if (files && files.length > 0) { var file = files[0][0]; var reader = new FileReader(); reader.onloadend = function() { var dataURL = reader.result; var content = dataURL.match(/,(.*)$/)[1]; helper.upload(component, file, content, function(answer) { helper.hide(component,event); if (answer=='Success') { }else{ var toastEvent = $A.get("e.force:showToast"); toastEvent.setParams({ ...

Lightning Spinner : Toast for LWC and Aura

Image
Lightning Spinner : Aura Component Aura Component : HTML Aura Component : CSS .THIS.spinner{ position: relative; display: inline-block; width: 51px; vertical-align: middle; white-space: nowrap; } Lightning Spinner : Lightning Web Component LWC : Template (HTML) Lightning Web Component : JS import { LightningElement, track } from 'lwc'; export default class Spinner extends LightningElement { @track loading = true; } Lightning Web Component : CSS .spinner{ position: relative; display: inline-block; width: 51px; vertical-align: middle; white-space: nowrap; } Note : You can hide spinner from JS via set loading=false attribute in both framework. Lightning Toast: Aura Component Just needed Call Standard Event to show : $A.get("e.force:showToast"); Aura Component : HTML Aura Comp...

Lightning Datatable for LWC and Aura

Image
Lightning DataTable : Aura Component LightningDataTableController(Apex Controller ) public class LightningDataTableController{ @AuraEnabled public static List<Contact> fetchAccountContacts(String accountId) { List<Contact> lstContact=new List<Contact>(); lstContact=[select id ,Name,Email,Phone from contact where accountid=:accountId]; return lstContact; } } LightningDataTable.cmp (Component) <aura:component controller="LightningDataTableController" implements="force:hasRecordId,flexipage:availableForAllPageTypes,force:lightningQuickActionWithoutHeader" access="global"> <aura:handler name="init" value="{!this}" action="{!c.doInit}" /> <aura:attribute name="data" type="Object"/> <aura:attribute name="columns" type="List" default="[{label: 'Name', fieldName: ...

Lightning Web Component and Lightning-Aura Component : Salesforce

Image
Lightning Web Component and Lightning-Aura Component : Salesforce Code Cheat Sheet for both Framework with Comparison 1. Component Bundles Lightning-Aura Component .comp : Markup or HTML Controller.Js : Client Side Controller Helper.Js : Client Side Util or Helper Controller Render.Js : Client Side Render Controller .css : CSS Resource for HTML .auradoc : Aura Documentation .design : Design Parameter for Builder .SVG : SVG Resource for Component Lightning Web Component .html : Markup or HTML Controller.Js : Client Side Controller .css : CSS Resource for HTML meta.xml : Design Parameter for Builder 2. JavaScript properties or Variables Lightning-Aura Component Lightning Web Component import { LightningElement, api, track } from 'lwc'; export default class fetchRecords extends LightningElement { @api recordId; @track sobject; } 3. Logical Operators Lightning-Aura Component //isLoading is a boolean attribute in Component Ligh...