Category Archives: Uncategorized

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.


Salesforce Integration with external Systems

In Salesforce for integrations before deciding on any approach ask yourself following questions so that you can make a better decision about an approach.

A. What is expectation of response. Is it instantaneous or can user wait? If user can wait then what is the threshold value for which user will wait?
Why: 1. If the response is returned in the same call then its very good, but if is giving request identifier then for fetching results you will need Schedulable batch option which can make callout and get the results for you. Always remember that this will delay the completion of whole cycle by min 2 mins to 15 min depending upon how sales force executes batch.
2. There is very hard limit of 10 callouts in a transaction so consider this before doing any architecture.

A. Generating XML by String concatenating?
1. Try to divide XML generation by dividing whole logic in methods.
2. Have one method for every kind of XML generation which cleans up the value based on type. Eg. Applying appropriate date format, handling null values. This gets varied based on the system with which you are integrating. So it gives you the ability to keep formatting things at common place.

B. What is the expected time of the response?
There is a limit of 120 seconds limit for overall call out time in a transaction and cap of 60 seconds for a single callout.

C. Are you sending any DB generated data in integration?
If you are sending any DB generated data like autonumber, then you need break transaction, since sales force does not allow any dml before the call out. Normally changing transaction means normally doing ajax call after the DML making transaction is done.

D. Do you need to store information received after making callout and handling network failure or system error?
So basically you are doing a DML after call out which is allowed, but just think what if the dml fails and you rolled back everything. But my friend you can not rollback the call out you had done, so have planning for such scenario like submitting the data again and asking the other end system to ignore the first call. This save lot of efforts and panic when system goes live.

If you have any integration related question please comment below. Happy learning!!

Executing common Javascript code at the end of every ajax request :)

Have you ever encountered a situation where you had to call some javascript code after a ajax request is complete and some area of page is reRendered. This normally is the case when your events, some extra UI related javascript gets vanished when elements gets reRendered. For that the solution is to have code inside a javascript function and call it on page load and in oncomplete of commandButton, commandLink, actionFunction etc (all these are ajax request). So for this kind of situation there is a better solution which provides you a place where you can write code which will get called when ever a ajax request is made from page. The trick is that when we do ajax request from page (by any means – commandButton, commandLink, actionFunction etc ) a instance of XMLHttpRequst is created and the ajax request is performed with the help of it. So we can override the method which gets called when the request is completed and put our Javascript code there to get executed. So say bye bye to overload of writting common and duplicate code in oncomplete of every ajax calling commandButton, commandLink etc 🙂 Hope this helps someone.