Using JWT Flow to Authenticate Nodejs application with Salesforce

Video tutorial and Complete source code to use Salesforce JWT OAuth to authenticate Nodejs Application

JWT OAuth uses digital signature to authenticate external application with Salesforce. JWT can be used to request an OAuth access token from Salesforce when a client wants to use a previous authorization.

Complete Source code is available here.

How JWT OAuth works
  1. Developer creates a connected app and provides digital certificate in OAuth settings. You can refer this post to understand how openssl can be used to create digital certificate locally.
  2. We need to make sure this connected app is already pre – approved either by using WebServer, User Agent or any other flow. You can find this step in video recorded.
  3. We need to generate JWT token and sign it with certificate. This code snippet is available in this file in method getJWTSignedToken_nJWTLib(). I have used njwt module of Nodejs to create a JWT token. This is very useful website to validate and generate JWT token as per digital certificate.
  4. Next we need to send JWT request to token URL –  https://login.salesforce.com/services/oauth2/token
  5. If JWT request is valid then Salesforce returns access_token , which can be used in subsequent requests to perform allowed operations in Salesforce via Nodejs application.

Continue reading “Using JWT Flow to Authenticate Nodejs application with Salesforce”

Salesforce Winter 18 Release – My Favorite Features

My favorite Salesforce Winter 18 features about Lightning, Flow, Platform Event , Shield and Salesforce DX

There are many cool features features in Winter 18, however I would be listing only my favorite top picks from 589 pages of release notes. Would suggest to through this post to understand Sandbox readiness dates for Winter 18.

You can check materials of this meetup as well organized by Amit, where I shared my favorite Winter 18 feature with sample code.

  1. New Lightning Base Components

Lightning Base components are out of the box component created with Salesforce Lightning Design System CSS. If there are no Lightning Base components, You would need to use aura or HTML components and write custom CSS to make look and feel similar to Lightning Experience. Base component starts with lightning: namespace. There are many new Base components introduced like lightning:datatable ,  lightning:checkboxGroup , lightning:dualListbox ,  lightning:progressIndicator , lightning:progressBar,  lightning:slider. Recently only I blogged about Read only Chevron Component with mountains of code. Even though we are using this component for last 6 months however If my project could have waited, then all I had to use is 5-6 lines of code using lightning:progressIndicator.

2. Component Library (Beta)

We can already see all standard and custom component information using https://<myDomain>.lightning.force.com/auradocs URL. However, as part of Winter 18 release, Salesforce came up with revamped website just like Lightning Design System to show code snippets on how to use Lightning Components. You can navigate to Component Library using https://<myDomain>.lightning.force.com/componentReference/suite.app URL.

3. Lightning Data Services (GA)

We are hearing about Lightning Data Services from almost last one year and finally its generally available for use. You can check this blog post on how to use it. Continue reading “Salesforce Winter 18 Release – My Favorite Features”

Enterprise Territory Management – Auto Account Assignment using Apex

Use Apex code to auto assign Accounts on basis of Enterprise Territory Assignment rules

Using Territory Management in Salesforce, we can auto assign territories to Account and give access to users working in common region. When we create Account, Territory Assignment rules automatically runs. On Account update we have a checkbox on page layout allowing to run Territory rules. However, Lightning experience does not support Territory Assignment checkbox yet on page layouts.

Unfortunately, Apex also does not support Account Assignment using Territory rules. Only way left is to use Salesforce API. Question is, just to run Enterprise Territory Management rules, should we import WSDL and convert it to respective Apex classes ? There must be some better way.

Then I remembered this article which I wrote around 5 years back. Instead of importing WSDL into Salesforce and converting it to Apex classes, we can take help of SOAP UI to find the request format and using HttpRequest, we can simulate request. Continue reading “Enterprise Territory Management – Auto Account Assignment using Apex”

Salesforce Path – Read Only Lightning Component

Author posted by Jitendra on Posted on under category Categories Salesforce and tagged as Tags with Leave a comment on Salesforce Path – Read Only Lightning Component

Chevron Component build in Lightning with Same look and feel as of Salesforce Path in read only mode

Salesforce Path is awesome feature, where you can display picklist value at top of record page and on click, it updates value in Salesforce database. However same solution does not fit in all scenario. Consider situation where picklist field is supposed to be changed by some other process or Integration. Now you don’t want anyone to change it from user interface. Even though you like Salesforce Path to show summary at top of page however it won’t be useful in above scenario.

Because of this, I created a Read Only Path Component in Lightning. I tried to keep same look and feel as of Standard Path component. This component will need only two inputs

  1. Record Id – It would be automatically passed if we use it using App Builder
  2. Field API Name – API name of picklist type of field

Now think about it. Only thing I got is Record Id. How would I know Object Name ? How would I know all picklist values for field name supplied ?

 With the help of this post, I will get Object name on basis of record Id.  And, with the help of this post, I will get Field Description. Hopefully you got it, I am talking about Dynamic Apex here 🙂 .

Continue reading “Salesforce Path – Read Only Lightning Component”

Winter 18 – Automatic Styling of Visualforce Pages in Lightning Experience

How to use lightningStylesheets attribute to render Visualforce in Lightning Experience Stylesheet

Reason I posted previous blog was to showcase life of Visualforce developer before and after Winter 18If we want to use same Visualforce in classic and Lightning experience then we had to check theme of logged-in user in Visualforce and render page section accordingly.

However, not any more. With Winter 18we have LightningStylesheet attribute available for apex:page tag. Below source code produces same output as of previous code, however no extra logic to detect and render page section as per logged in user theme. Continue reading “Winter 18 – Automatic Styling of Visualforce Pages in Lightning Experience”

Use Visualforce in Classic and Lightning Experience

How to design a Visualforce page so that It would be displayed properly in classic as well in Salesforce Lightning Experience

This topic was subset of my presentation in Salesforce Boston World Tour 2017. Sometimes we find our-self in situation where custom Visualforce page should be displayed with Old theme in classic but with Lightning theme in Lightning Experience.

If you can convince client to use same user interface in classic and Lightning, then it would be an ideal approach. Even Salesforce displays classic user interface for many setup pages inside Lightning experience.

If client does not agree, then we simply need to detect that in which context Visualforce is running and then enable or disable the section as per UIThemeDisplayed global variable as shown in below Apex code snippet. Continue reading “Use Visualforce in Classic and Lightning Experience”

Performing Load Testing in Salesforce using Selenium and TestNG

Parallel execution of browsers in Selenium with the help of TestNG and determining maximum operating capacity of custom code in Salesforce

When we build any custom solution in Salesforce, key is to write an efficient and meaningful Apex test classes for sure. However sometime we may need to test how custom application would behave in maximum operating capacity. Here, I am talking about Load Testing of custom applications built on top of Force.com platform. Recently I needed to push my code to its limit to know how many concurrent users can use it before hitting any governor limits. Quickly I realize that its time to call my friends Selenium and TestNG.

Before doing any extensive stress or load testing on Salesforce, we must need to contact Salesforce support and explain them what we are trying to achieve. More detail available in this official Salesforce blog post.

I have published some blog posts about Selenium in past as well however whats different this time ? I need to determine after how many simultaneous user interactions, I would hit Concurrent Apex Limit error as shown in below image.

Salesforce Governor Limit error - Concurrent Apex Limit
Salesforce Governor Limit error – Concurrent Apex Limit

Continue reading “Performing Load Testing in Salesforce using Selenium and TestNG”

Housie / Tambola / Bingo Game Number Generator

Author posted by Jitendra on Posted on under category Categories Others and tagged as Tags with Leave a comment on Housie / Tambola / Bingo Game Number Generator

Online free Housie / Tambola / Bingo Game. Simple to use and play with Bingo Number descriptions

Its not education , technical or Salesforce related post. Its source code of Family fun game Tambola.

Free online Tambola Game
Free online Tambola Game

This weekend, we all friends gathered together to play one of most famous Indian game Tambola. This game is also known as Housie or Bingo.  Normally there is central pot where numbers between 1 to 90 placed in piece of paper or plastic balls. Host reveals numbers one by one by randomly selecting those balls or piece of papers from pot. Problem for us were, we all have children and there is no way they will allow us to play with this way. Instead of host picking numbers, our kids would have been played with those. So what I did is, simple HTML page with random number generator between 1 to 90. Plugged my laptop to chromecast and voila, everyone in room playing traditional game in modern way 😉 Continue reading “Housie / Tambola / Bingo Game Number Generator”

Lightning Data Service – Standard Controller for Lightning Components

Best Practices for Salesforce Lightning Component. How Lightning Data Service can improve Lightning Component performance and solve inconsistent data problem without writing single line of Apex code. Demo source code, image and slides included.

If you have worked on Visualforce and started playing with Lightning Component, you must have identified one important missing feature, which is standard Controller.

Lets assume a scenario, you have two Lightning Components on Account page. One Lightning Component is used to show some fields and other component is used to edit same record.

Problem 1 :

To achieve this, both Lightning components would invoke Apex method separately at the cost of performance, by issuing duplicate server calls. Below image depicts problem, where multiple Lightning component requests same content by making separate server calls.

Lightning Components - Duplicate Server Calls
Lightning Components – Duplicate Server Calls

Continue reading “Lightning Data Service – Standard Controller for Lightning Components”