Tuesday 30 December 2014

Salesforce icons: Going native for visual appeal!

Think visually appealing applications in Salesforce and automatically you tend to think of Javascript, HTML5, jQuery and so on! But hold on a second! Remember Bible? “Seek within and thou shalt find!” Salesforce has a sophisticated set of icons that cover most of your icon requirements. No Javascript, no jQuery, just plain simple, reliable Salesforce! Let me show you how.


When do you need icons?

Suppose you are building a formula field to classify a Lead as Hot, Warm or Cold! Or you need to prioritize your Cases as Critical, Medium and Low! Or build sophisticated looking Visualforce pages on Salesforce…basically do anything that needs to be visual and appealing, Icons help to provide an appealing visual indicator for your otherwise boring numerical or textual business data.


Great! How do I do that?

Let’s say you need a visual indicator on your Invoices that are marked as pending, paid or overdue. We will use a simple formula field to accomplish this. Let’s assume you have a custom object Invoice (Invoice__c) which maintains and tracks the Invoice data. A picklist field Status (Status__c) tracks the payment status of the Invoice and has the following options as shown below. For this example, let’s assume that the business logic is already in place to demarcate an Invoice with any of the below mentioned statuses.


We will leverage the flag icon available with Salesforce to provide visual indicators. For a green flag, usually indicative of active health, we will use the URL:  https://<your salesforce instance>.salesforce.com/img/samples/flag_green.gif to provide visual indicators. Replace your Salesforce org’s instance in the initial part of the URL in order to access the specific icons. 

Some icons that you can use in this scenario are given below:
  • Pending – Yellow flag
  • Paid – Green flag
  • Overdue – Red flag 
Now let us create a new formula field having a return type as Text on the Invoice object and call it Payment Status. This field is created in order to display the visual indicator and the invoice status concatenated together. The formula for Payment Status would be as shown below: 


Now, add the newly created Payment Status field to the Invoice page layout. Create some Invoice records and bask in the glory of your creation!! 



Remember!!!

Although this approach is a convenient way to access and leverage icons already being used by Salesforce, these images are susceptible to modifications or getting deleted during any of the new Salesforce upgrades. Hence, a better way to access the same images would be through the wonderful Graphics Pack app provided by Salesforce Labs on AppExchange. You can install the app on your Salesforce instance from the following link -
 https://appexchange.salesforce.com/listingDetail?listingId=a0N30000004cfIcEAI

The links mentioned below provide the ability to preview most of Salesforce’s standard images and also get their relative paths with ease. Kudos to them!!


In my next blog, I will talk about how this can be further leveraged on Visualforce pages.

Written by Jigar Shah, Solution Architect at Eternus Solutions
Read More »

Wednesday 24 December 2014

NEED FOR SPEED……Response Times Demystified


   At 140 miles on the information super-highway, world was just whizzing by…. The adrenaline rush that I was experiencing was nothing that I had ever foreseen. This was AMAZING!!!! And just than an inaudible SCREECH and…sudden death!!!!! The application had suddenly died on me….For the mission critical application I was working with, the last thing I needed was a delayed response time…This was a deal-breaker! I could sense the client breathing down my neck and snarling at this abrupt HALT if this ever happened in Production!!!

   I suddenly broke into a sweat…..my mind was running overtime to figure out the way to overcome this challenge NOW!!!! While researching on the response time issue, I stumbled upon the concept of local storage and client side caching ….. An inner voice whispered to me: “This is where the answer to my problem lies!” I started exploring the concept in-depth and that’s what I thought I should share with you.


“Why Go LOCAL?”


   Think Real –Time and Local storage is the way to go….make this your thumb rule and the response time issue will be “HISTORY”

While Local Storage sounds fancy and geeky, it really is nothing but storage available on client side which can be used by different browsers and native applications to store large amount of data (up to 5 MB), without affecting browser performance.

Real time applications like traffic updates, share-market updates and medical applications totally survive on the response time and cannot have a delay in response or data acquisition, which is when local storage comes into play. Local storage reduces the response time for these applications as it uses locally cached data.

   These applications work on the concept of locality of reference which manage to capture the particular user centric data and store it in local cache. As a result, the response time is much faster. Every user displays a pattern while using any application. By using local storage, you can cache the data that is more frequently accessed by the user.


Local Where?


In my case, my client needed the response time for search results to be as near real-time as can be…. Typically, the users would enter the search string and with the insertion or deletion of each character, the search results would need to change instantly.


How I re-built my Rome?


  • The user enters the string to search the provider name in the available text box. The string is then matched with available provider names in the local cache
  •  There are two types of searches that are performed
    • Exact key match which matches the string or key exactly to the available names in the local cache
    • Possible key match which finds possible matches to the string/key.
  •  If there are no matches found in the local storage, a remote call to server is made and results are retrieved from the server. In that case, the local cache is updated with the particular key search where a local match was not found. The local cache will also store this key so that it can be utilised for future searches made by the user.
  •  For every record that is stored in local cache, a TTL (Time to Leave) is set. If a record is found in cache, its TTL is reset. TTL ensures that only those records which are searched frequently are stored in the cache and those records with a low search frequency are eliminated when their TTL expires. If the user searches the same key or prefix string to the key again, results are retrieved from the local cache.
  • Even after the results are found in the local cache, we always have a remote call to the server for the following purposes:
    • To update the cache entries, if the same record is updated on the server. This is important so as to avoid stale data in local cache because even though we would get faster result searches with local cache, that data won’t be of any use if it is out of sync with the server.
    • To append any new records matching the search criteria.
    • To update the TTL.


“The Secret “(code snippet for Local Storage)




   This function would store the number of times the user has clicked the button. Even when the session is closed, the click count is stored in the local storage, so that whenever the user starts the session, the click count is incremented from the last checkpoint, i.e. the count stored in the local storage.


Improve & Prove, so that they APPROVE….






   This time tracker displays the response time for key search in the application where local storage was implemented and we could see the response time being reduced substantially.


And in the end….


   Local cache may not be a replacement for real server side storage, however, it can be used to speed up pages by caching results from API or by caching complex structures created by JavaScript. It can be used to cache data generated on client side or data that is used recursively by the client, hence resulting in a faster and efficient application for the user. Therefore, even though it is not a replacement for server side storage, it actually enhances it considerably.


References



All’s well that ends well…a happy client, a happy manager and a happy and a little more enlightened me…. Life couldn’t have been better…till I came across my next challenge!!!! 



Written by Sahil Dhatrak, Salesforce Developer at Eternus Solutions
Read More »