Posts

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...

Calling Apex method from a Custom Button and Submit to Approval Process

Image
To call Apex method from a Custom Button and Submit to Approval Process : Salesforce 1. Create a custom button {!REQUIRESCRIPT("/soap/ajax/15.0/connection.js")} {!REQUIRESCRIPT("/soap/ajax/15.0/apex.js")} var approval = confirm("Are you sure want to send it for approval process?"); if(approval == true) { sforce.apex.execute("ApprovalSubmit","sentToApproval",{recordId:"{!Interviewer__c.Id}"}); alert("Set Record for Approval"); } 2. Create a apex class : global class ApprovalSubmit{ webservice static void sentToApproval(Id recordId) { Approval.ProcessSubmitRequest req1 = new Approval.ProcessSubmitRequest(); req1.setComments('Submitted for Approval'); req1.setObjectId(recordId); Approval.ProcessResult res = Approval.Process(req1); } } Happy Sharing... Everyone has their own favourites, so p...