Differences between the ways resources are referenced in href/src

Sometimes small items takes too much of time. I always face issues when it comes to providing correct location of the resource so this post is an effort to minimize such issues.

Let’s understand differences in which resources are referenced. Consider the index.html has script in below ways:

    <script src="myscripts.js"> 
  1. Browser will look in the current directly of the file where this script tag is mentioned. So if you move the index.html into any other directly then browser will not be able to reference the myscript.js
  2. <script src="./myscripts.js"></script>
  3. This will be exactly same as example in #1. This is only different way of mentioning that refer the file from the current directory.
  4. <script src="/myscripts.js"></script>
  5. Here browser will look into the root directory of the website, no matter where the index.html having this tag is present.
  6. <script src="../myscripts.js"></script>
  7. Here browser will go to the parent directory of the index.html and then will look for the myscript.js

This blog post is small but thought of sharing, whenever I used to face issue then I used to try different formats and some or the other used to work. Never paid close attention but if you have so many file references and then your try outs permutation and combination increases. Having clear understanding of how references work would save some hassles.


Scheduled Report Export using Analytics API in Apex

In salesforce we cannot have scheduled email export. Below solution could help to get the scheduled export of the reports as CSV. For this I have used “Execute a Custom Action” feature when we subscribe to email notification. Salesforce has provided feature where Apex code can be executed if the condition specified while subscribing report is met.

Screen Shot 2017-04-08 at 7.11.30 PM

EmailReportExport class

You can use code from : https://gist.github.com/kiran-machhewar/ff0f2ca55b89b793ad88973f7701feb0

In order to get the scheduled export of Report data, report has to be subscribed and while subscribing report select “Execute a Custom Action” and select EmailReportExport class. As per the schedule provided as soon as the conditions are met then execute method from EmailReportExport will get invoked. In the execute method csv data is created by Analytics api in Apex.

Subscribe the report in below way:

Screen Shot 2017-04-08 at 7.47.10 PM

When the condition for the report subscription is met at scheduled time you will get the email notification as in below snapshot:

Screen Shot 2017-04-08 at 7.50.53 PM


  1. No email limits are consumed since email would be sent to the user who has subscribed the email.
  2. Same EmailReportExport handler can be used with different reports.


Only 2000 records will be available as a csv export.

Happy learning  🙂


Integration via Outbound Messages-SF API Call Manager

This article is for exploring integration possibilities via outbound messages and solving below problems:

  1. Timeout issue – In salesforce there is strict limit of 120 seconds for callout. This could be solved if API calls are carried outside of salesforce like in heroku app where no such limit for callout is there.
  2. API Calls which requires polling – Polling for response becomes difficult in salesforce as in order poll for result batch is required which runs at regular interval but there cannot be more than 5 batches running simultaneously. This can be solved by implementing polling logic in heroku app where threading could be used for polling and making inbound call to salesforce when results are available.

This idea came up when I was having discussion with my colleague Tushar Kaore on integration approaches. We thought that lets try to analyze the performance and reliability of outbound messages in integration.

Here is the design of this framework:


Integration via Outbound Messages

Lets see how this would work

  1. Whenever API Call has to be made then in salesforce API Call record has to be created which would include below details
    • Endpoint
    • Request
    • Headers
  2. On create of such API Call records salesforce would initiate an outbound message call to the heroku application with all the details which would be required to make API call
  3. Actual API Call will be made by heroku app to the external system. Here an API call which takes more than 120 seconds can be made and it is required to do polling then heroku app can handle that by polling in regular intervals of time.
  4. Heroku app will receive the response.
  5. Inbound API call would be made to salesforce to pass on the response received by heroku app.
  6. Response would be updated in API Call record and on trigger of API Call record response could be processed and proper actions could be taken.

In this structure two applications are involved Salesforce App and Heroku app.

Steps to configure app:

  1. Heroku App: Install the Heroku App  : heroku-api-call by using deploy to heroku button from repository home page.
  2. Salesforce App: Insall the Salesforce App : sf-api-call by using Deploy to Salesforce button from repository home page.
  3. Configure workflow rule: Create workflow rule on API Call object with the outbound message action as per below screenshot.


    Outbound Message Action

  4. Add Remote Site setting: Add the remote configured endpoint as remote site setting.

How to test:

Create an API Call record in salesforce with the endpoint. As soon as the record gets created salesforce will make outbound message call to heroku app. Heroku app will make API call to the endpoint and it will be update the received response to salesforce via making inbound api call.

I will be be testing this for performance and will check its reliability to use in production applications. Currently only GET API calls are supported and will update the code to have below featues:

  1. Headers support
  2. POST call support

features list will go on…..

Whenever real time integration is not required and this approach could be used to solve issues of

  1. Callouts taking more than 120 seconds
  2. Whenever polling for response is required.

Result of this exercise:

I created nearly 50K API calls (thats lots of API calls) and tried to see how many API calls will get processed by this mechanism. Results are very promising


Results shows that 20K API calls are fulfilled within 3 minutes i.e. 113 fulfilled API call/second. My heroku instance was bombarded with outbound messages calls and now it is down.. 🙂

Note these are the results with free heroku instance with one dyano only. So imagine if you have a heroku app with good number of dynos to fulfill requrest then you can think of very promising results.

API Call is made to http://headers.jsontest.com/ for testing.

Happy learning and keep exploring..


Disabling standard style sheets – Salesforce

Everywhere we have lightning and Salesforce is in process to provide all classic features in lightning. In this process there would be some features which would not be available in lightning. So sometimes we need to use the best of both worlds classic and lightning. Here is similar problem and its solution.

Problem : Custom click to dial functionality can be used in visualforce pages with the below code

<apex:page standardController="Account" showHeader="true">
    <support:clickToDial         number="415-555-1234"         entityId="001XB000000HFUM"         params="myparam1,myparam2"     />

Ref: https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_support_clickToDial.htm

As of now this only works with the visualforce page where showHeader is enabled. Now if we enable showHeader then visualforce includes standard style sheets but then such standard style sheets  could get mixed up with LDS in visualforce page and creates css conflict issues.

Solution : Lets consider what we want here-

  1. ShowHeader = true, on page level showheader has to be enabled other wise click to dial functionality from visualforce page would not work.
  2. Don’t want any impact on lightning design system css

Here solution is to dynamically remove the standard style sheets which gets loaded because of showheader set to true. The problem with that approach is that whenever any section of page is reRendered then standard style sheets are loaded back which again distorts the LDS css. There is one way to solve this is instead of removing standard stylesheets disabling it by below code:

 function disableStandardStylesheets(){ 
          if(this.href.indexOf('/sprites/')!=-1 &amp;&amp; this.href.indexOf('/CTI.css') == -1){ 
               $(this).attr("disabled", "disabled");

Advantage of disabling standard style sheets instead of removing is that after every reRender it will not get loaded back. This solution will other places in Salesforce where you want to disable effect of any standard stylesheets gets loaded by Salesforce.


Visualforce page with LDS and Standard Style Sheets


Visualforce page with LDS and disabled Standard Style Sheets

User Creation in Salesforce

This post is for the best practices to be kept in mind while loading users in the system. If client business users starts getting notification when they are not supposed to then that could create chaos. Below are the points which needs to be considered while loading users in the system.

  1. User Template: User data should be gathered before hand, to make sure that we are not missing any information which we are supposed to be asked to client. Template should be used so that no data would be missed. Attached is the user template using which we could ask client to provide all user details UsersTemplate.
  2. SSO consideration: If the salesforce org is using SSO then federation id should be asked before hand and should be part of user template.
  3. Multicurrency: If salesforce org uses multicurrency then it would be good to include that CurrencyIsoCode column in the user template.
  4. External Id: No matter how much you plan but you could have some wrong data like incorrect firstname, lastname etc. It would be a good practice to create external id in user object so that users could be upserted and data could be corrected.
  5. Email Id change: Whenever user’s email ids are changed then users gets notification for confirming the email address and also notification is sent to the email id which you are changing. If you want to change the email ids without any notification to users then you can turn of the Email Deliverability to “No Access”. This will make sure that email id is changed without creating any chaos of notifications.
  6. Reset Password: Whenver user loading process is going on it would be good to turn off Email Deliverability. When you think that now its the time to welcome users then you can reset the password. Users will get the email to set their passwords.
  7. Feature Licenses: If you want to activate some feature licenses then that could be added as a part of user template.


    Feature Licenses

  8. Welcome Email: If you want to send welcome emails to user for helping with the documents to understand salesforce and with next steps. To implement this you would need to create email template and which would be used by workflow rule on user object.

Above list could act as a checklist for your plan of creating users in salesforce.

Using Picklist in Integrations- After Spring 17 Release

In integrations mainly information is communicated to other System by passing id/code values instead of Labels. In Salesforce picklist has values and labels but before Spring 17 release there was not provision to have different value and label for picklist items.

Whenever different Label has to be shown to user and different code has to be passed to other system then some workarounds were required to be done like having code label mapping in code or keeping code values in custom object and passing those values in integrations. Such solutions were error prone and requires maintenance since in code it is required to do String comparison to get the proper code to be sent to other system.

Now we have a relief, in Sprint 17 salesforce has provided much required feature where we can have separate code and label for picklist items.


Different code and label


Apex code showing how to get Label and Code which could be used while passing data in integrations to other system

Now using this we could minimize the extra maintenance which was required initially. This is a great feature and should be considered in integrations.

Communication between Lightning Component and VisualForce

I have been playing with lightning components. Now it has confirmed that Salesforce is going to use only lightning and will provide most of its features via lightning experience. So how can we move from visualforce to lightning. Visualforce and lightning components uses different design methodologies MVC vs MVCC. So its not very easy to get migrated from visualforce to lightning once. There is a hope, salesforce has provided lightning out by which we can add lightning component in visualforce page. Isn’t that great? So we can start building lightning component and start including it in visualforce and gradually replace visualforce with lightning.

But in this migration process we would have some functionality in visualforce and some of the functionality in lighting. Now here we would want that visualforce should be able to communicate with lightning components and lightning components should be able to communicate with visualforce page. By this there are limitless possibilities of mashup of lightning components with visualforce.

Here below code demonstrates how lightning event model could be used to have communication between visualforce component and lightning component.

Code for LightningOutExampleController

Code for LightningOutExample component:

Code for LightningOutExampleController.js

Code of lightning out events:




Visualforce page:

In the code you can see we have used lightning event model to call methods from visualforce which are in lightning and vice versa.

I tried to have this as demo by exposing this page on site but unfortunately lightning out is currently not supported on pages hosted on public site.

This code is also present on public repo which you can check:



Now you can experiment with lighting components in visualforce and create awesome implementations.