Show Record Completeness using Salesforce Lightning API

Salesforce introduces cool new feature with every release. Recently with Spring 17 they introduced Lightning API. Which REST API based and it will return layout, records, fields information and other stuff.

The advantage with this is you can get all details of an object or record and show it on any preferred UI on mobile or on your own website. For more details read the official documentation here.

What I did is to use this API to show the record completeness using AngularJS and Google charts.  Like this ..

Screen Shot 2017-05-25 at 7.31.36 PM

How it is done ?

One of the Lightning API is

/services/data/v{version}/lapi/record-ui/{recordId}

This will give me the record object details, fields details and data information etc. I just  took the field data information and checked which fields have value or not. First create a VF page using StandardController (if you need to add on record page like I did).

var recordId = '{!Account.Id}';
$http.get('/services/data/v39.0/lapi/record-ui/'+recordId,{headers: {'Authorization': 'Bearer {!$Api.Session_ID}'}})
.success(function(data, status, headers, config) {
   $scope.data = { totalFields : 0 , populatedValues : 0 };
   angular.forEach(data.records[recordId].fields,function(record,key){
      $scope.data.totalFields = $scope.data.totalFields+1;
         if(record.value != '' && record.value != undefined){
             $scope.data.populatedValues = $scope.data.populatedValues+1;
         }
   });
});

Since it is REST API I am calling it using $http.get method of AngularJS. Same thing available in other JavaScript frameworks because it is just JavaScript. How to use AngularJS ? for that checkout my blogs on AngularJS Part 1 and Part 2

The above code is just for getting the count. Showing it in different ways like adding charts and other styling is up to you. You can make it as fancy or simple as you want. One other simple way …

Screen Shot 2017-05-25 at 7.37.27 PM

Note :- The current way gets all the fields, if you want layout specific fields and their comparison, then you iterate  data.layouts it contains all the information of sections and their fields.

Thank You

Let me know if you have any comments…

Advertisements

One thought on “Show Record Completeness using Salesforce Lightning API

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s