{"id":6401,"date":"2018-03-01T03:35:47","date_gmt":"2018-03-01T03:35:47","guid":{"rendered":"https:\/\/www.jitendrazaa.com\/blog\/?p=6401"},"modified":"2018-05-09T19:38:39","modified_gmt":"2018-05-09T23:38:39","slug":"implementing-custom-apex-adapter-for-salesforce-connect","status":"publish","type":"post","link":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/implementing-custom-apex-adapter-for-salesforce-connect\/","title":{"rendered":"Implementing Custom Apex Adapter for Salesforce Connect"},"content":{"rendered":"<p style=\"text-align: justify;\">As you might already know, using <a href=\"https:\/\/www.jitendrazaa.com\/blog\/tag\/salesforce-connect\/\"><strong>Salesforce Connect<\/strong><\/a>, 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 <strong>Salesforce Connect<\/strong> to show data like using protocols OData 2 or OData 4, cross org adapter , custom Apex adapter etc.<\/p>\n<p style=\"text-align: justify;\">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.<\/p>\n<p style=\"text-align: justify;\">Using <strong>Salesforce Connect\u00a0<\/strong>in above scenario will cut down your most of effort. Your data would be exposed as <a href=\"https:\/\/www.jitendrazaa.com\/blog\/tag\/external-object\/\">External Object<\/a> 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.<\/p>\n<p style=\"text-align: justify;\">Now, here your challenge comes. It is pretty much possible that external data does not support\u00a0<strong>OData\u00a0<\/strong>protocol. And you don&#8217;t have necessary middleware tool available to perform transformation and expose it as OData. It doesn&#8217;t mean that you cannot use Salesforce Connect. One of the feature of Salesforce Connect is writing and using\u00a0<strong>Custom Adapter using Apex.<\/strong><!--more--><\/p>\n<p style=\"text-align: justify;\">Lets have a fun and build very simple\u00a0<strong>Custom Adapter for Salesforce Connect using Apex.<\/strong><\/p>\n<p style=\"text-align: justify;\">For this blog post, we would be using <a href=\"https:\/\/www.healthcare.gov\/api\/blog.json\">this free API<\/a> 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.<\/p>\n<figure id=\"attachment_6467\" aria-describedby=\"caption-attachment-6467\" style=\"width: 720px\" class=\"wp-caption aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-6467\" src=\"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2018\/03\/Cross-Org-Adapter-Page-1.png?resize=720%2C402&#038;ssl=1\" alt=\"Implementing Cross Org Adapter in Salesforce\" width=\"720\" height=\"402\" srcset=\"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2018\/03\/Cross-Org-Adapter-Page-1.png?w=720&amp;ssl=1 720w, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2018\/03\/Cross-Org-Adapter-Page-1.png?resize=300%2C168&amp;ssl=1 300w\" sizes=\"auto, (max-width: 720px) 100vw, 720px\" \/><figcaption id=\"caption-attachment-6467\" class=\"wp-caption-text\">Implementing Cross Org Adapter in Salesforce<\/figcaption><\/figure>\n<p style=\"text-align: justify;\">First, we will need to create a class which extends\u00a0<a href=\"https:\/\/developer.salesforce.com\/docs\/atlas.en-us.apexcode.meta\/apexcode\/apex_class_DataSource_Connection.htm\">DataSource.Connection<\/a> and then define\u00a0<strong>sync\u00a0<\/strong>method. This method would have information about schema for all table and columns available to Salesforce Connect.<\/p>\n<p><script src=\"https:\/\/gist.github.com\/JitendraZaa\/bee0c55a427399a5a7d8a0a133b2a385.js\"><\/script><\/p>\n<p style=\"text-align: justify;\">Next, we would need to override\u00a0<strong>query\u00a0<\/strong>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 <a href=\"https:\/\/developer.salesforce.com\/docs\/atlas.en-us.apexcode.meta\/apexcode\/apex_class_DataSource_TableResult.htm\">Database.TableResult<\/a> 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 <a href=\"https:\/\/developer.salesforce.com\/docs\/atlas.en-us.apexcode.meta\/apexcode\/apex_class_DataSource_QueryUtils.htm?search_text=QueryUtils\">DataSource.QueryUtils<\/a> 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.<\/p>\n<p><script src=\"https:\/\/gist.github.com\/JitendraZaa\/3d13b45a8524bad4672e1cb2d78f3785.js\"><\/script><\/p>\n<p style=\"text-align: justify;\">Now, all left is to create a Provider class by extending <a href=\"https:\/\/developer.salesforce.com\/docs\/atlas.en-us.apexcode.meta\/apexcode\/apex_class_DataSource_Provider.htm?search_text=Provider\">DataSource.Provider<\/a>. 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<\/p>\n<p><script src=\"https:\/\/gist.github.com\/JitendraZaa\/989e66fa809a77cbb42db63c7e2b1bc6.js\"><\/script><\/p>\n<p>Demo<\/p>\n<figure id=\"attachment_6403\" aria-describedby=\"caption-attachment-6403\" style=\"width: 833px\" class=\"wp-caption aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-6403\" src=\"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2018\/03\/Apex-Adapter-for-Salesforce-Connect.gif?resize=833%2C621&#038;ssl=1\" alt=\"Custom Apex Adapter for Salesforce Connect\" width=\"833\" height=\"621\" \/><figcaption id=\"caption-attachment-6403\" class=\"wp-caption-text\">Custom Apex Adapter for Salesforce Connect<\/figcaption><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Complete Source code and demo of implementing Custom Apex Adapter for Salesforce Connect<\/p>\n","protected":false},"author":1,"featured_media":6405,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"jz_research_post":"","_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[9],"tags":[431,433,432],"class_list":["post-6401","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-salesforce","tag-external-object","tag-odata","tag-salesforce-connect"],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2018\/03\/Custom-Apex-Adapter-for-Salesforce-Connect.png?fit=1053%2C607&ssl=1","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":4102,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/salesforce-faq-part-20-lightning-questions\/","url_meta":{"origin":6401,"position":0},"title":"Salesforce interview question related to Lightning framework &#8211; Part 20","author":"Jitendra","date":"February 4, 2015","format":false,"excerpt":"Salesforce interview questions for Salesforce developers and admin , mostly related to newly released Salesforce Lightning components and applications","rel":"","context":"In &quot;Salesforce&quot;","block_context":{"text":"Salesforce","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":6975,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/salesforce-integration-patterns-best-practices-with-video\/","url_meta":{"origin":6401,"position":1},"title":"Salesforce Integration Patterns &#038; Best Practices &#8211; with Video","author":"Jitendra","date":"February 2, 2020","format":false,"excerpt":"When to use which integration patterns in Salesforce along with best practices. Video to show how to use Outbound message to integrate Salesforce without writing code","rel":"","context":"In &quot;Salesforce&quot;","block_context":{"text":"Salesforce","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/"},"img":{"alt_text":"Integration Patterns in Salesforce","src":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2020\/02\/Integration-Patterns-in-Salesforce.png?fit=1200%2C425&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2020\/02\/Integration-Patterns-in-Salesforce.png?fit=1200%2C425&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2020\/02\/Integration-Patterns-in-Salesforce.png?fit=1200%2C425&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2020\/02\/Integration-Patterns-in-Salesforce.png?fit=1200%2C425&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2020\/02\/Integration-Patterns-in-Salesforce.png?fit=1200%2C425&ssl=1&resize=1050%2C600 3x"},"classes":[]},{"id":4698,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/my-favorite-appexchange-products\/","url_meta":{"origin":6401,"position":2},"title":"Top Salesforce tools , AppExchange and Heroku applications","author":"Jitendra","date":"July 1, 2015","format":false,"excerpt":"List of all my favorite Appexchange products, Heroku applications , Git repository , Free Source codes and some important Blog posts in Salesforce","rel":"","context":"In &quot;Salesforce&quot;","block_context":{"text":"Salesforce","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/"},"img":{"alt_text":"Top Salesforce Tools","src":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2015\/07\/Top-Salesforce-Tools.png?fit=1200%2C675&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2015\/07\/Top-Salesforce-Tools.png?fit=1200%2C675&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2015\/07\/Top-Salesforce-Tools.png?fit=1200%2C675&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2015\/07\/Top-Salesforce-Tools.png?fit=1200%2C675&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2015\/07\/Top-Salesforce-Tools.png?fit=1200%2C675&ssl=1&resize=1050%2C600 3x"},"classes":[]},{"id":4942,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/salesforce-winter-16-top-features\/","url_meta":{"origin":6401,"position":3},"title":"Salesforce Winter 16 &#8211; Top features","author":"Jitendra","date":"October 28, 2015","format":false,"excerpt":"You can watch recording of my live stream channel as well to know more on Winter 16 features.\u00a0Powerpoint presentation used in livestream can be accessed from here. 1. Object Manager Objects are objects, even if they are standard or custom objects. Salesforce simplified navigation to access Objects, we can access\u2026","rel":"","context":"In &quot;Salesforce&quot;","block_context":{"text":"Salesforce","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/"},"img":{"alt_text":"Setup Audit Trail - Salesforce Winter 16","src":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2015\/10\/Setup-Audit-Trail.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2015\/10\/Setup-Audit-Trail.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2015\/10\/Setup-Audit-Trail.jpg?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2015\/10\/Setup-Audit-Trail.jpg?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":4174,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/salesforce-interview-questions-part-22\/","url_meta":{"origin":6401,"position":4},"title":"Salesforce Interview Questions &#8211; Part 22","author":"Jitendra","date":"December 1, 2015","format":false,"excerpt":"Consider it Facts or FAQ or interview questions but its small and important notes about Salesforce. More than 200 interview questions for Salesforce developer, Admin and consultants","rel":"","context":"In &quot;Salesforce&quot;","block_context":{"text":"Salesforce","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/"},"img":{"alt_text":"220+ Salesforce Interview Questions","src":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2015\/11\/220plus-Interview-Questions-1024x303.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2015\/11\/220plus-Interview-Questions-1024x303.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2015\/11\/220plus-Interview-Questions-1024x303.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":28,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/salesforce-interview-questions\/","url_meta":{"origin":6401,"position":5},"title":"Salesforce Interview Questions &#8211; Part 1","author":"Jitendra","date":"May 6, 2010","format":false,"excerpt":"Set of most often asked questions on the salesforce.com developement","rel":"","context":"In &quot;Salesforce&quot;","block_context":{"text":"Salesforce","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/6401","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/comments?post=6401"}],"version-history":[{"count":4,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/6401\/revisions"}],"predecessor-version":[{"id":6468,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/6401\/revisions\/6468"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/media\/6405"}],"wp:attachment":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/media?parent=6401"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/categories?post=6401"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/tags?post=6401"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}