Custom Apex Adapter for Salesforce Connect

Implementing Custom Apex Adapter for Salesforce Connect

As you might already know, using Salesforce Connect, we can display external data in Salesforce without physically creating record. Before Salesforce Connect, we had few options like Visualforce, Canvas etc. There are few options available in Salesforce Connect to show data like using protocols OData 2 or OData 4, cross org adapter , custom Apex adapter etc.

There could be scenario, like you already have license for Salesforce connect and want to use it to expose external data inside Salesforce. If you think about any custom solution using Lightning component or Visualforce, there could be many considerations and most important would be displaying data on user interface.

Using Salesforce Connect in above scenario will cut down your most of effort. Your data would be exposed as External Object and you can use it just like custom object. Just imagine, how cool it would be that you would not need to write a single line of code for data presentation.

Now, here your challenge comes. It is pretty much possible that external data does not support OData protocol. And you don’t have necessary middleware tool available to perform transformation and expose it as OData. It doesn’t mean that you cannot use Salesforce Connect. One of the feature of Salesforce Connect is writing and using Custom Adapter using Apex.

Lets have a fun and build very simple Custom Adapter for Salesforce Connect using Apex.

For this blog post, we would be using this free API which returns JSON of healthcare blogs in Spanish and English language. There is no need of any kind of authentication in this example, which will make it a lot simpler.

Implementing Cross Org Adapter in Salesforce
Implementing Cross Org Adapter in Salesforce

First, we will need to create a class which extends DataSource.Connection and then define sync method. This method would have information about schema for all table and columns available to Salesforce Connect.

Next, we would need to override query method. This would be executed by Salesforce connect whenever any SOQL issued against this external object or list view or detail page is viewed. Now, this is the method where most of logic would be executed. Calling external API, parsing it to return as Database.TableResult format. Typically, searching, sorting or pagination should be implemented at external server. However, in our case healthcare API does not has any capability to search, sort or perform pagination. And in-fact, it worked in favor of our post so that I can demonstrate how Salesforce DataSource.QueryUtils class can be used to filter, sort and implement pagination. Would like to remind that DataSource.QueryUtils are good for demo purpose however you should not use it in production.

Now, all left is to create a Provider class by extending DataSource.Provider. This class will inform Salesforce Connect that which authentication mechanism is supported and what are the capabilities. Capability includes ability to create, update, delete, view or search record. Complete source code for this post is available below


Custom Apex Adapter for Salesforce Connect
Custom Apex Adapter for Salesforce Connect




Related Posts


7 responses to “Implementing Custom Apex Adapter for Salesforce Connect”

  1. […] Implementing Custom Apex Adapter for Salesforce Connect […]

  2. cloudmattersblog Avatar

    Great post. Happened to be discovering same topic last week, for somewhat different reason – as loopback adapter scenario into the same org. Very similar to described in the 10y old Idea 😉

  3. Francis Pindar Avatar

    What I love about External Objects is the fact that they don’t need to be external objects at all… but you can expose internal objects & meta data… ever wanted to create a report on Deleted opportunities? now you can, ever wanted to create a report on manual sharing rules? Now you can… all that data and fields you haven’t been able to create a report from before, now you can! I say a bit more in my Dreamforce session:

    1. Esteve Graells Avatar

      Love that video!!

  4. Jitendra Avatar

    Thanks for sharing youtube video Francis

  5. Anil s Avatar

    hi Jitendra – thanks for this post, i was trying to learn about this and this is very useful. I am confused about two things if i may
    1. How do we setup a data service for this connector, i believe most of the scenarios and examples we are using an existing service like northwinds or the one you use healthcare blog. How different are these services from any rest service that was traditionally used, do they have to be changed to support the connector?
    2. Does this support Ligthning experience? when i tested it doesnt and shows a error message to switch back to classic, but i see any example by salesforce where they show it in LEX screen. Is it possible to be used in LEX then? I dont see any documentation very clearly if its supported in LEX or not

  6. Sravanthi Avatar

    Can we have multiple external tables included in a single custom adapter class ?

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from Jitendra Zaa

Subscribe now to keep reading and get access to the full archive.

Continue Reading