Posts

Two-factor authentication using LWC

Use Case: In this blog we are going take the use case to build "Two-factor authentication (EMAIL)" using Lightning Web Component. This use case is going to be helpful to place an extra layer of security, especially when when we try to expose Salesforce sensitive data using Public Sites (or) Communities. Code Components: Below we are going to use 3 main code components to implement Two-factor email authentication. 1. CommonUtility.cls : Apex class that has two methods. One method to generate unique 6 digit code using crypto class and another method to generate single email message and dispatch email. public with sharing class CommonUtility { @AuraEnabled(cacheable= true ) // Method to send 6 digit two-factor email verification public static String twoFactorGen(String usrEmail) { String verCode = genUniqueCode(); // generate unique 6 digit code Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage(); // ins...

Change Data Capture - Asynchronous Trigger Processing

Image
In Salesforce there are multiple ways of processing data Asynchronously using " Batch Apex ", " Schedule Apex ", " Queueable Apex ", and " Future Method ". In Summer '19 release, there is another feature available called " Asynchronous Apex Triggers " that can process data Asynchronously with the help " Change Data Capture ". With Change Data Capture enabled for any specific object (Custom and Standard) in Salesforce, it begins publishing events every time when a record is created or updated or deleted or undeleted. Change Data Capture supports all custom objects and for list of supported standard object, here is the Link . Change Data Capture Setup: In order to enable Objects for receiving change notifications, navigate to Setup-->Integrations-->Change Data Capture, select object to add and click Save. Asynchronous Apex Trigger: Once Change Data Capture is enabled on an object, events are published and ...

Lightning Web Components (New Programming model for building Lightning Components)

Image
Salesforce has recently introduced a new developmental model for building Lightning Components called Lightning Web Components which can coexist and interoperate with the original Aura Programming model, and deliver unparalleled performance! In this blog post, we are going to build a basic Lightning Web Component using VS Code IDE with Salesforce CLI prerelease sfdx plugin. Prior to that for this demo I have already signed up for a free 'Spring '19 - Pre-Release' org and upgraded my SFDX plugin to pre-release version by running below command in my Terminal (This step is required only until February 9th, 2019). "sfdx plugins:install salesforcedx@pre-release" Next we need to add the "Lightning Web Components" extension for VS Code. In my VS code IDE, once I create my project and authorize my pre-release org now I should see a new folder called 'lwc' created under force-app-->main-->default folder! Now go ahead and...

Callable Interface in Salesforce Apex

Image
With Winter '19 release new Callable Interface has been introduced, which helps in calling methods dynamically between Apex classes or triggers, even for code that works in separate packages. Class has to implement "Callable" interface along with a method "call(String action, Map args)" which has a return type of Object. Below is the sample Apex code using callable interface using. CallableApexTest.apx: /* * Purpose: To test new Callable Interface * Date: OCT302018 */ public class CallableTest2 implements Callable { // Method to return month of the year Integer method1(Date d) { Integer month = d . month(); return month; } // Method to return boolean if passed integer is same as current month Boolean method2(Integer mnth) { if (method1(System . today()) == mnth) { return true; } else { return false; ...

Using JavaScript Promises in Lightning Components

Image
With JavaScript being a single threaded process by nature, using "JavaScript Promises" it makes JavaScript to be a multithreaded or in other words it is a process of making Asynchronous calls using JavaScript. JavaScript Promises is a native JavaScript functionality that can be used in Lightning Components. Salesforce recommends using ECMAScript 6 (ES6, often referred to as “Harmony”) which is a standard script language. In case if the browser doesn’t provide a native version, the framework uses a polyfill so that promises work in all browsers supported for Lightning Experience. Basic Syntax for Promises: var promise = return new Promise(function(resolve, reject) { setTimeout(resolve, 100 , 'foo' ); }); Promise can return either resolve (If the result is success) and reject (If the result is fail). Optionally there is one more status called pending. Now let's go ahead and build a simple Lightning Component that will output some user information like...