Tutorials

How to add sparklines to Salesforce | Census

Sean Lynch
Sean Lynch July 02, 2020

Sean is co-founder and Chief Product Officer (CPO) at Census. He loves enabling data-driven organizations, so he's energized by introducing the world to Data Activation. San Francisco, California, United States

Last week we received an email from one of our customers: “Can I put sparklines on our accounts in Salesforce? It would be amazing to see usage growth over the past six weeks visually.” I agreed that would be amazing, but I was doubtful. Maybe a fancy AppExchange app could help, but out of the box, images aren’t a Salesforce field types so I thought they were out of luck.

But with a little digging, we discovered a hidden little Salesforce feature: Formula fields have an Image function. And then this happened:

Now our customer has a live sparkline showing the real-time growth of every customer right on their Salesforce Account record. Today I’m going to show you how to set that up for yourself!

Get the data into Salesforce

The first step is to get the data points that will power your sparkline into Salesforce. We do this in our sleep at Census (literally, you can schedule your syncs to run at any hour of the day, or even continuously), so I’ll walk through how to do that with Census though you could also use the Salesforce API or any other method to update the field.

Here I’m calculating the datapoints over the last six weeks and then I join them into a comma separated list. That’s the value we’re going push into Salesforce that we’ll use for our sparkline, you’ll see why it’s a comma separated list in a minute. My last step is to take this new datapoint and push it into a text field in Salesforce.

The datapoints field is currently visible on my Salesforce Account records so that I can verify data is being synced correctly, but it’s just going to be powering the graph in a moment so you could also hide it from your page layout once you’re done.

Graphing the data

We’ve got our datapoints in Salesforce and Census is happily keeping them up to date. How do we show that as a sparkline? We’re going to use that image function I mentioned and a great service called QuickChart.

You can think of Quickchart as an API for creating graphs. You provide datapoints in a URL and it instantly renders the graph and returns the image. They happen to have a pre-built Sparkline style, which we’ll use with our datapoints field.In Salesforce, I create a new field on my Account called Growth (Last 6 Weeks), and make it a Formula type. The formula is the magic that ties it all together:

  • Uses the Image function
  • To make a call to the QuickChart API service
  • And passes the comma separated data points in the field that Census is populating


IMAGE(
  'https://quickchart.io/chart?bkg=white&c={ type: "sparkline", data: { datasets: [{ data: [' + Sparkline_Datapoints__c + '] }] }}', 'Account Growth Sparkline', 20, 100)

You can see we use the comma separated list from the Sparkline_Datapoints__c field and then create a URL that includes that value and passes it to QuickChart. And here’s the result. If you modify the data in the datapoints field, Salesforce will send those values to QuickChart and they’ll update the graph instantly. Boom! Live sparklines, directly inside Salesforce. No AppExchange app necessary.

Just another super power for Census customers. And if you need a hand getting your live data into Salesforce, contact us and we will show you how easy it can be!

Related articles

Customer Stories
Built With Census Embedded: Labelbox Becomes Data Warehouse-Native
Built With Census Embedded: Labelbox Becomes Data Warehouse-Native

Every business’s best source of truth is in their cloud data warehouse. If you’re a SaaS provider, your customer’s best data is in their cloud data warehouse, too.

Best Practices
Keeping Data Private with the Composable CDP
Keeping Data Private with the Composable CDP

One of the benefits of composing your Customer Data Platform on your data warehouse is enforcing and maintaining strong controls over how, where, and to whom your data is exposed.

Product News
Sync data 100x faster on Snowflake with Census Live Syncs
Sync data 100x faster on Snowflake with Census Live Syncs

For years, working with high-quality data in real time was an elusive goal for data teams. Two hurdles blocked real-time data activation on Snowflake from becoming a reality: Lack of low-latency data flows and transformation pipelines The compute cost of running queries at high frequency in order to provide real-time insights Today, we’re solving both of those challenges by partnering with Snowflake to support our real-time Live Syncs, which can be 100 times faster and 100 times cheaper to operate than traditional Reverse ETL. You can create a Live Sync using any Snowflake table (including Dynamic Tables) as a source, and sync data to over 200 business tools within seconds. We’re proud to offer the fastest Reverse ETL platform on the planet, and the only one capable of real-time activation with Snowflake. 👉 Luke Ambrosetti discusses Live Sync architecture in-depth on Snowflake’s Medium blog here. Real-Time Composable CDP with Snowflake Developed alongside Snowflake’s product team, we’re excited to enable the fastest-ever data activation on Snowflake. Today marks a massive paradigm shift in how quickly companies can leverage their first-party data to stay ahead of their competition. In the past, businesses had to implement their real-time use cases outside their Data Cloud by building a separate fast path, through hosted custom infrastructure and event buses, or piles of if-this-then-that no-code hacks — all with painful limitations such as lack of scalability, data silos, and low adaptability. Census Live Syncs were born to tear down the latency barrier that previously prevented companies from centralizing these integrations with all of their others. Census Live Syncs and Snowflake now combine to offer real-time CDP capabilities without having to abandon the Data Cloud. This Composable CDP approach transforms the Data Cloud infrastructure that companies already have into an engine that drives business growth and revenue, delivering huge cost savings and data-driven decisions without complex engineering. Together we’re enabling marketing and business teams to interact with customers at the moment of intent, deliver the most personalized recommendations, and update AI models with the freshest insights. Doing the Math: 100x Faster and 100x Cheaper There are two primary ways to use Census Live Syncs — through Snowflake Dynamic Tables, or directly through Snowflake Streams. Near real time: Dynamic Tables have a target lag of minimum 1 minute (as of March 2024). Real time: Live Syncs can operate off a Snowflake Stream directly to achieve true real-time activation in single-digit seconds. Using a real-world example, one of our customers was looking for real-time activation to personalize in-app content immediately. They replaced their previous hourly process with Census Live Syncs, achieving an end-to-end latency of <1 minute. They observed that Live Syncs are 144 times cheaper and 150 times faster than their previous Reverse ETL process. It’s rare to offer customers multiple orders of magnitude of improvement as part of a product release, but we did the math. Continuous Syncs (traditional Reverse ETL) Census Live Syncs Improvement Cost 24 hours = 24 Snowflake credits. 24 * $2 * 30 = $1440/month ⅙ of a credit per day. ⅙ * $2 * 30 = $10/month 144x Speed Transformation hourly job + 15 minutes for ETL = 75 minutes on average 30 seconds on average 150x Cost The previous method of lowest latency Reverse ETL, called Continuous Syncs, required a Snowflake compute platform to be live 24/7 in order to continuously detect changes. This was expensive and also wasteful for datasets that don’t change often. Assuming that one Snowflake credit is on average $2, traditional Reverse ETL costs 24 credits * $2 * 30 days = $1440 per month. Using Snowflake’s Streams to detect changes offers a huge saving in credits to detect changes, just 1/6th of a single credit in equivalent cost, lowering the cost to $10 per month. Speed Real-time activation also requires ETL and transformation workflows to be low latency. In this example, our customer needed real-time activation of an event that occurs 10 times per day. First, we reduced their ETL processing time to 1 second with our HTTP Request source. On the activation side, Live Syncs activate data with subsecond latency. 1 second HTTP Live Sync + 1 minute Dynamic Table refresh + 1 second Census Snowflake Live Sync = 1 minute end-to-end latency. This process can be even faster when using Live Syncs with a Snowflake Stream. For this customer, using Census Live Syncs on Snowflake was 144x cheaper and 150x faster than their previous Reverse ETL process How Live Syncs work It’s easy to set up a real-time workflow with Snowflake as a source in three steps: