Salesforce

Salesforce Evergreen : A game changer!

Hey all! This blog post will introduce you to the serverless environment which runs inside the Salesforce Platform!  You might have guessed it by the title “Salesforce Evergreen” it is!

We would also discuss about the possibilities and solution designs achievable using this powerful feature.

Salesforce Evergreen was introducted at Dreamforce 2019 as a new addition to the Customer 360 Platform that brings in serverless functions based on fully-managed Kubernetes, support for open programming languages and commonly used high-performance data stores.

Thus allowing developers to leverage the Open Souce Programming Platforms such as Node JS to build functions as a service which can be invoked using workflows.

Evergreen brings in and adds a whole new dimension to the platfrom providing features alike :
  1. Functions-as-a-Service : for writing business logic and event processing in languages like Node.js, Java and Apex, using the full power of those languages’ package ecosystems. Functions can be triggered directly from Apex or using Platform Events, with many more invocation types and event sources to come.
  2. Microservices: for building serverless HTTP apps and APIs that can be quickly evolved by small agile teams and composed into complex, engaging digital experiences. Services and functions are serverless, consume no resources when idle and automatically and elastically scale with traffic.
  3. Managed data stores like Postgres, Apache Kafka and Redis that complement the Salesforce Data APIs for high-performance persistence and real-time eventing.

Evergreen is a seamless part of the Salesforce platform and no extra authentication or networking setup is required. For example, developers can invoke functions directly from Apex, run logic with org-context and query and write-back updates.

Evergreen provides a framework for bringing together the original platform concept and a tradition of supporting low-code development along with the latest Heroku development methods.

02-v11-1

Evergreen is based on Kubernetes and balances control and access to scalable container technology by providing a fully managed serverless service operated by Salesforce. This service lets you focus more on innovation rather than infrastructure operations. Evergreen opens Salesforce development to any development team because apps, functions and services can be built using common open languages, tools and technologies.

Let’s say you have an existing application with complex functionalities running on Java which consumes data from a External System. Now with Evergreen introduced you can migrate the functionality to serve as a “Evergreen Function” and deploy it to the platfrom to use it natively from a single place “Your Salesforce Org.”

Once you have deployed your function, you can simply call the function developed using Java/Node JS by using low code tools such as : workflows. This removes the barrier between different development platforms.

No matter which environment you develop, your functions can be consumed easily just with clicks and serve the purpose all from the single place “Your Salesforce Org.”!!

“Apex” is a wondeful language but it cannot serve/meet some complex functionalities which needs you to leverage other Programming Languages or Open Source Platform runtime Environment like “Node JS”.

With Nodejs you can potentially exploit the entire npm ecosystem to build interesting services.

Evergreen follows a “Pay for what you use” model, if there is no consumption of the function/resources you need not pay for them. You pay for what you use!

If you are aware of the AWS Platform this might sound familiar to “AWS Lambda” which is an event-driven, serverless computing platform provided by AWS.

The only difference is Evergreen is out of the box feature provided by Salesforce and sits/tightly integrates with the platform. Allowing us to create large scale, highly performant architecture. You can start to think big possibly without worrying about the platform limits.

Let’s discuss some of the features/functionalities which can be achieved using Evergreen.
  1. Salesforce Lightning platform has great many options to integrate with external system except FTP for e.g. you cannot directly send a CSV file to an FTP location. There are app exchange apps but they send data through their servers which may or may not be acceptable depending on the regulation you may have to follow. You should be able to connect to an FTP folder via a service deployed on Evergreen and send data from Salesforce.
  2. Evergreen supports the high performant Redis Database, a key-value based database which can be utilised for processing high volumes of data along with Kafka. This can be utilised in designing a high performant low latency based Content Management Systems leverage multiple clouds.
  3. Custom notifications and event monitoring services can be designed with notification services built on top of Evergreen.
  4. With a large number of libraries available in “NPM” AI/Machine Learning solutions on top of Salesforce will become even easier if we have access to Java and/or Nodejs toolkits that can interact directly with data in Salesforce.

Evergeen is still in “Developer Preview” and expected to be GA later in 2021.

We would need to install a lot of pre-dependencies and packages before we can start developing Evergreen Functions!

Let’s quickly look at some code samples to understand how we can create functions and leverage them.

This scenario was presented at DF’19 let’s have a quick recap and go through it!!

Scenario :  Guest check-in experience using Evergreen

 ” The Lightning Platform is used to quickly create an employee-facing iOS app for managing housekeeping and room-readiness and that is seamlessly extended with event-driven functions running on Evergreen. When housekeeping marks a room as ready using the employee app, a platform event triggers a Node.js function that uses guest-context to send a tailored real-time notification letting the guest know that the room is ready for early check-in.

At the end of the stay, the Salesforce Flow powering the guest checkout can call out to a different function with invoicing details. The Node.js function can use the invoice details and an npm PDF module to quickly generate a bill. Here’s the sample function that receives the request as a CloudEvent fetches additional data, generates a PDF and adds a link to the PDF from the guest booking record. “


import { UnitOfWork, SObject } from '@salesforce/functions';
import { PDFDocument } from 'pdfkit';
import * as fs from 'fs';

module.exports = async function(event, context, logger) {
const folioPayload = event.payload;

// Creating a new Unit Of Work instance
const uow = UnitOfWork;

// Run SOQL query to fetch folio data
const query = `SELECT Id, Description__c, Amount__c, Date__c FROM Booking_LineItems__c WHERE Reservation__c =
'${folioPayload.recordId}'`;
const folioLineItems = await context.sfApi.query(query);

// Call function to generate PDF and store in external data store
// for Files Connect
const pdfFilesConnect = await generatePdf(
folioPayload.recordId,
folioLineItems
);

// Update the booking object
const ReservationObject = new SObject('Reservation__c');
ReservationObject.Id = folioPayload.recordId;
ReservationObject.Status__c = 'Paid and Folio created';
uow.registerModified(ReservationObject);

// Update data
uow.commit();
};

async function generatePdf(id, lineItems) {
# generate and store folio PDF
}

Another example below shows querying of records from the Account Object and displaying it over the logs using Evergreen Functions.

Screenshot (539)

There are lot more things to be explored once this feature rolls out!!

Hope you have enjoyed reading this blog post, and learnt something new! Thanks for reading and keep #Trailblazing!!

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s