Posts

Server-Side Document Generation

Image
Document Generation                  With Document Generation , you can generate contracts, proposals, quotes, reports, non-disclosure agreements, service agreements, and so on. Client-side document generation  requires a user interaction and generates documents using an OmniScript. Salesforce provides sample OmniScripts and Integration Procedures that you can use and customize to implement these capabilities. Server-side document generation   typically doesn’t require user interaction. Instead, a backend server processes requests to generate documents. Let’s examine the differences between client-side and server-side document generation.   Client-Side Document Generation 

Reusable Code in OmniScript - Lightning Web Components

Lightning Web Components are great for breaking down layouts and interfaces into small, reusable pieces. Step 1: Create Lightning Web Component BaseComponent is via a BaseComponent folder in the standard LWC folder of a SFDX project. Export and Import Inside baseComponent.js, we can define reusable functions and export them for use in other components. In the example below, I define a function called convertToArray and export it BaseComponent import { LightningElement } from 'lwc' ; import { OmniscriptBaseMixin } from 'vlocity_cmt/omniscriptBaseMixin' ; export default class BaseComponent extends OmniscriptBaseMixin ( LightningElement ) { } export function convertToArray ( obj ) { if ( obj instanceof Array ) { return obj ; } else { return [ obj ]; } } Child Component import { LightningElement , api , track } from 'lwc' ; import { OmniscriptBaseMixin } from 'vlocity_cmt/omniscriptBaseMixin' ;

Communicating between Independent LWC in Omniscript

Image
This is a simple example that shows a button that, when clicked, publishes a message. This shows how two separate custom LWCs can communicate with each other inside of an OmniScript. Below is the overall design using the Pub/Sub model. So, lets get started! Step 1: Create a LWC component and use below code to fire events with parameters to pass an omniscript and component to Community Page. Below is the HTML and JS code for reference. SampleLWCComponent.html < template > < lightning-button label = "Send Event" onclick = {handleClick} ></ lightning-button > </ template > SampleLWCComponent.js import { LightningElement } from 'lwc' ; import pubsub from 'vlocity_ins/pubsub' ; export default class SampleLWCComponent extends LightningElement { handleClick ( e ){ let accId = '0015g00000gWY8VAAW' ; pubsub . fire ( "handlePubSubEventChange" , "result" , { "accId" : ac

Import third party JS library in OmniScript Custom Lightning Web Components

 Import third party JS library in OmniScript Custom Lightning Web Components This post explains how to import third-party libraries in omniscript custom lightning web components(lwc). We can not directly import the third party scripts in Lightning web components because Security purpose. We will get error as  "This page has an error. You might just need to refresh it. Error in $A.getCallback() [Assertion Failed!: Scoped imports not allowed when a runtime namespace is specified" Salesforce restrict the importing scripts from third-party content delivery sites like cdnjs, jsdelivr, etc.  Firstly, you need to download the scripts from third-party sites. Then upload the scripts in static resources. Syntax import { loadScript } from 'lightning/platformResourceLoader' ; import { OmniscriptBaseMixin } from 'vlocity_cmt/omniscriptBaseMixin' ; platformResourceLoader  have two methods  loadStyle , and  loadScript.  For both methods return type is Promise. load

Efficient way to write apex code

Image
Set.contains(element) Vs List.contains(element)  Guess What if I tell small things Matter!!!                     If you’re having a cup of tea, pause for a moment because next two minutes will reveal something simple yet less known it the world of Salesforce                     Set && List your favorite go to during the typical development cycle. But going forward you will definitely double check before using them. For Instance, look at this example                     Take two set of collections (Set<Integer> and List<Integer>). Now the crux of the discussion which one will give better performance. Lets get technical Which will give better performance Set or List ?      a.     I f collection is List :  List < Integer > listInteger = new List < Integer > (); for (Integer i = 0; i < 100000; i++) { listInteger.add(i); } Long start = DateTime.now().getTime(); System.debug('get ' + listInteger.contains(100000)); Long finish = DateTime.now

Salesforce Best Features available

Image
 Salesforce Code Samples & Best Features available: 1. Get merged body without extra effort. EmailTemplate  emailTemplate = [Select Id FROM EmailTemplate where name =  'Test1' ];   Messaging . SingleEmailMessage  email = Messaging.renderStoredEmailTemplate(emailTemplate.Id, userinfo.getUserId(),AccountObj.Id); system.debug(email.plainTextBody); 2.  Business Hour Calculations example in apex: public   static   Boolean  checkBusinessHour(){          //business hour logic          List < BusinessHours > defaultBusinessHours = [SELECT  Id FROM  BusinessHours  WHERE  Name = 'Default'   AND  IsDefault =  TRUE  AND  IsActive = TRUE   Limit   1 ];                   // Find whether the time is within the default business hours          return  BusinessHours.isWithin(defaultBusinessHours[ 0 ].id, System.now());     } 3. Check boolean expression in apex: public   class  BooleanEx

JWT (JSON Web Token)

Image
Introduction to JSON Web Tokens JSON Web Token (JWT) is an open standard ( RFC 7519 ) that defines a compact and self-contained way for securely transmitting information between parties as a JSON object. This information can be verified and trusted because it is digitally signed. JWTs can be signed using a secret (with the  HMAC   algorithm) or a public/private key pair using  RSA  or  ECDSA . When should you use JSON Web Tokens? Here are some scenarios where JSON Web Tokens are useful: Authorization: This is the most common scenario for using JWT. Once the user is logged in, each subsequent request will include the JWT, allowing the user to access routes, services, and resources that are permitted with that token. Single Sign On is a feature that widely uses JWT nowadays, because of its small overhead and its ability to be easily used across different domains. Information Exchange: JSON Web Tokens are a good way of securely transmitting information between p