{"id":37,"date":"2023-06-18T00:57:56","date_gmt":"2023-06-17T23:57:56","guid":{"rendered":"http:\/\/salesforcerahul.com\/?p=37"},"modified":"2023-06-19T16:26:04","modified_gmt":"2023-06-19T15:26:04","slug":"using-3rd-party-appexchange-apis-without-additional-licenses","status":"publish","type":"post","link":"https:\/\/salesforcerahul.com\/?p=37","title":{"rendered":"Using 3rd party AppExchange APIs without additional licenses"},"content":{"rendered":"\n<p>I recently came across a requirement to generate an excel file for a community user. The file is generated by leveraging a 3rd party AppExchange product&#8217;s API. The file can be generated only when the context user has a license assigned to it . We did not want to give license to the community user . We utilized the platform event to change the context user(to user with license) to do the callout and saved on additional licenses.<\/p>\n\n\n\n<p><strong>Requirement <\/strong>:: On click of a button in the LWC , an excel file get generated &amp; downloaded in the local machine with records data. A third party AppExchange product is used to generate the file and no additional code is done for the spreadsheet generation. <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"1024\" height=\"532\" src=\"http:\/\/salesforcerahul.com\/wp-content\/uploads\/2023\/06\/save-license-1024x532.jpeg\" alt=\"\" class=\"wp-image-39\" srcset=\"https:\/\/salesforcerahul.com\/wp-content\/uploads\/2023\/06\/save-license-1024x532.jpeg 1024w, https:\/\/salesforcerahul.com\/wp-content\/uploads\/2023\/06\/save-license-300x156.jpeg 300w, https:\/\/salesforcerahul.com\/wp-content\/uploads\/2023\/06\/save-license-768x399.jpeg 768w, https:\/\/salesforcerahul.com\/wp-content\/uploads\/2023\/06\/save-license.jpeg 1104w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>This pattern uses :: 1) LWC component (for end user interaction ) 2) Apex class (to publish the platform event) 3) Platform events( One to capture the information about requesting user &amp; Second to send the files information to the LWC component)   4) Trigger on Platform Event(This run as a user with license to do the callout) <\/p>\n\n\n\n<p>In the above diagram, a LWC component is used as the UI for the community user.  There is a button on the LWC component . The user clicks the button &#8211;&gt; a Platform event is published using apex &#8211;&gt; the trigger fires on the platform event (Context user is changed to the the user with 3rd party tool license) &#8211;&gt; Callout to the 3rd party file generation API &#8211;&gt; File gets generated in content document object &#8211;&gt; Platform event is created with public distribution link of the file &#8211;&gt; LWC listened to the Platform event using cometD library subscription &#8211;&gt; File is downloaded in the local machine.<\/p>\n\n\n\n<p>The context user is set by deploying the PlatformEventSubscriberConfig object file (you can find more information regarding this file from salesforce documentation)<\/p>\n\n\n\n<p><br><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I recently came across a requirement to generate an excel file for a community user. The file is generated by leveraging a 3rd party AppExchange product&#8217;s API. The file can be generated only when the context user has a license assigned to it . We did not want to give license to the community user &#8230; <a title=\"Using 3rd party AppExchange APIs without additional licenses\" class=\"read-more\" href=\"https:\/\/salesforcerahul.com\/?p=37\" aria-label=\"More on Using 3rd party AppExchange APIs without additional licenses\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[5],"tags":[8,10,9,7,6],"_links":{"self":[{"href":"https:\/\/salesforcerahul.com\/index.php?rest_route=\/wp\/v2\/posts\/37"}],"collection":[{"href":"https:\/\/salesforcerahul.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/salesforcerahul.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/salesforcerahul.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/salesforcerahul.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=37"}],"version-history":[{"count":7,"href":"https:\/\/salesforcerahul.com\/index.php?rest_route=\/wp\/v2\/posts\/37\/revisions"}],"predecessor-version":[{"id":60,"href":"https:\/\/salesforcerahul.com\/index.php?rest_route=\/wp\/v2\/posts\/37\/revisions\/60"}],"wp:attachment":[{"href":"https:\/\/salesforcerahul.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=37"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/salesforcerahul.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=37"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/salesforcerahul.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=37"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}