invention

"Real Life" Salesforce.com Dashboard

by corycowgill

Published on December 30, 2014

What is cooler than recreating your very own Salesforce.com Dashboards in real life with some cardboard, markers, and some littleBits! Recreate those virtual dashboards as "real life" dashboards using littleBits CloudBit!


How To Make It

1

For this example I created a Salesforce.com Summary Report. The report summarizes the total amount (value) of Opportunities that have a Stage of "Closed Won". Once you create the report you can create the dashboard with the report as the data source. Create a gauge chart in your dashboard and set the minimum amount to 2 million and the maximum amount to 5 million. The gauge chart maps well to the Servo littleBit.

2

The littleBit Servo has two basic modes: Step and Turn. In turn mode you can move the Servo to a specific degree based on the voltage you pass to the Servo. You can set the voltage from 0 to 100. The littleBit Servo has an arc of 145 degrees. So you will lose some precision as you can only set integer voltage values. Set the littleBit Servo to "Turn" mode. To give a rough voltage value you can take the range of values in your gauge (5 million max - 2 million min - 3 million range) / 145 degrees = 20689 dollars per degree in the chart. The amount of voltage is 1% of voltage = 1.45 degrees (145 degrees / 100% voltage = 1.45 volts percentage per degree).

3

Call the Salesforce.com Analytics API to get the values from the Opportunity Report. You can use the following Apex Class which will call the Salesforce.com API and convert the values into the appropriate voltage for the littleBit API. public class LittleBitsReportManager { public static LittleBitsManager.LittleBitsOutputPayload runOpptyGaugeReport() { // Get the report ID List reportList = [SELECT Id,DeveloperName FROM Report where DeveloperName = 'Opportunities_Won']; String reportId = (String)reportList.get(0).get('Id'); // Run the report Reports.ReportResults results = Reports.ReportManager.runReport(reportId, true); System.debug('Synchronous results: ' + results); // Run a report synchronously // Get the first down-grouping in the report, in this case the StageName = 'Closed Won' on Oppty's Reports.Dimension dim = results.getGroupingsDown(); Reports.GroupingValue groupingVal = dim.getGroupings()[0]; // Construct a fact map key, using the grouping key value String factMapKey = groupingVal.getKey() + '!T'; // Get the fact map from the report results Reports.ReportFactWithDetails factDetails = (Reports.ReportFactWithDetails)results.getFactMap().get(factMapKey); // Get the first summary amount from the fact map Reports.SummaryValue sumVal = factDetails.getAggregates()[0]; System.debug('Summary Label: ' + sumVal.getLabel()); System.debug('Summary Value: ' + sumVal.getValue()); //Set the output voltage as a percent. More voltage will send the Servo farther down the gauge. //Guage Chart = 0% Voltage = 2 Million (Minum Amount on Gauge) //Gaute Chart = 100 Voltage = 5 Million (Maximum Amount on Gauge) //16666 = 1 voltage percent (3 million between Min and Max / 145 degrees for the servo) //2 Million is the bottom of gauge so subtract that from the start. integer outputPercent = math.round((((Decimal) sumVal.getValue()) - 2000000) / 20689.655); integer duration = -1; //Set the voltage peermamently until it is overwritten LittleBitsManager.LittleBitsOutputPayload outputPayload = new LittleBitsManager.LittleBitsOutputPayload(outputPercent,duration); System.debug(JSON.serialize(outputPayload)); return outputPayload; } }

4

Using the same Apex Class "LittleBitsManager" I created in the previous post you can call the CloudBit to set the Servo to match the Dashboard Gauge in Salesforce.com. You can find that code here: http://corycowgill.blogspot.com/2014/12/calling-littlebits-cloudbit-from.html This simple line of code will reuse our code from the previous article and use the new code above to call the CloudBit. LittleBitsManager.sendOutputReq(LittleBitsReportManager.runOpptyGaugeReport()); Executing this line of code will make the "Real Life" Dashboard match the Dashboard in Salesforce.com. Let's see it in action!

Related Projects