Saturday, October 12, 2019
Wednesday, October 9, 2019
PDF Reader as a Salesforce Lightning Web Component
This is a Lightning web component based on PDF.js library to render a PDF document (an unencoded string representation of the PDF blob) inside an
iframe
.Check the code below for this component:
https://github.com/iamsonal/lwc-pdfReader
Tuesday, October 1, 2019
A basic Salesforce to Salesforce integration using REST API and OAuth
You can use a connected app to request access to Salesforce data on behalf of an external application. For a connected app to request access, it must be integrated with the Salesforce API using the OAuth 2.0 protocol.
1. Create a connected app in one of the Salesforce instances as below:
You will need to replace the callback URL after the completion of step 2.
2. Create an Auth Provider. Replace the consumer key and secret with the values.
Replace the callback URL in the connected app with the callback URL generated while creating this auth provider.
3. Create a named credential
4. Some Apex code
1. Create a connected app in one of the Salesforce instances as below:
You will need to replace the callback URL after the completion of step 2.
2. Create an Auth Provider. Replace the consumer key and secret with the values.
Replace the callback URL in the connected app with the callback URL generated while creating this auth provider.
3. Create a named credential
4. Some Apex code
HttpRequest req = new HttpRequest();
req.setEndpoint('callout:Cross_Org_Report/services/data/v45.0/query?q=select+Email,FirstName,LastName+from+contact');
req.setMethod('GET');
Http http = new Http();
HTTPResponse response = http.send(req);
return response.getBody();
Sunday, August 18, 2019
LWC: Implementing Service Components
A service component is a component that provides an API for a set of functionalities. Ideally, the service should be specialized, generic and reusable. Also, it does not have a markup, i.e. it is not visible by default.
Creating a custom service simplifies component’s code and help reduce code duplication. This in turns makes the code more robust and facilitates maintenance.
To develop a custom service component for my Account object, I have created an
accountService
component and exposed the below services:searchAccount
: it accepts a search key and returns the list of accounts matching the keygetAccounts
: this returns a list of 5 accounts
accountComponent
which is consuming the services like below:Please see the below repo for the code:
https://github.com/iamsonal/lwc-service
References:
https://developer.salesforce.com/blogs/2018/08/implement-and-use-lightning-service-components.html
Saturday, August 17, 2019
LWC: Modularizing Code using Singleton pattern
Imagine that we have a custom LWC component, which we drag-and-drop onto a Lightning page in Lightning App Builder. This component has 2 design attributes for First Name and Last Name. We need a way to access these values from any component without communicating down the containment hierarchy. Setting the public properties of child components becomes a tedious job if there are nested components.
To solve this issue, we can use the Singleton Pattern, which states that the number of instances of an object must be restricted to one only, hence the "single" in Singleton. The intent of the Singleton is ensuring a class has only one instance, and providing a global point of access to it.
For the sake of simplicity, I have created 2 components
component1
and component2
where component2
is the child of component1
. I need to access the design attribute values of the parent component from the child component. In this example, we are storing the design attribute values in a single central place, sharedData
component, written in the Singleton pattern.customLabels
using Javascript classes to access the custom labelsPlease see the below repo for the code:
https://github.com/iamsonal/lwc-singleton
Subscribe to:
Posts (Atom)