{"id":6439,"date":"2024-02-06T07:09:00","date_gmt":"2024-02-06T07:09:00","guid":{"rendered":"https:\/\/www.greytrix.com\/blogs\/salesforce\/?p=6439"},"modified":"2024-10-17T12:28:04","modified_gmt":"2024-10-17T12:28:04","slug":"how-to-invoke-lightning-auto-launched-flow-from-the-apex-class","status":"publish","type":"post","link":"https:\/\/www.greytrix.com\/blogs\/salesforce\/2024\/02\/06\/how-to-invoke-lightning-auto-launched-flow-from-the-apex-class\/","title":{"rendered":"How to invoke lightning Auto launched Flow from the Apex class"},"content":{"rendered":"\n<p>We will talk about how to call a Lightning Auto-launched flow from the Apex class in this blog post.<\/p>\n\n\n\n<p>The flow in Salesforce can be launched without user Interaction such as from a process builder or the apex code. So here we are creating a auto launched flow and call it through the apex code.<\/p>\n\n\n\n<p>Let\u2019s take a simple example to understand how to call a lightning flow from the apex.<\/p>\n\n\n\n<h1 class=\"wp-block-heading has-vivid-red-color has-text-color has-link-color wp-elements-16cc015e037dc143f9edbd94cfe972d6\"><strong>Example<\/strong><\/h1>\n\n\n\n<p>In this example, we are getting the value of Opportunity Stage name based on the opportunity id that we are passing from the apex code.<\/p>\n\n\n\n<p>Firstly, we have created lightning auto launched flow in which we have created two variables first is <strong>recordId<\/strong> and it is set as \u2018<strong>available for Input\u2019 <\/strong>and second is <strong>Opportunitystage<\/strong> which is used to send output to the apex class, and it is set as \u2018<strong>available for Output\u2019. <\/strong>Kindly refer below image.<\/p>\n\n\n\n<h2 class=\"wp-block-heading has-vivid-red-color has-text-color has-link-color wp-elements-3de7d5fcbf273f1ceda14de43f718b84\"><strong>1.<\/strong> <strong>RecordId Variable<\/strong><\/h2>\n\n\n\n<center><a href=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-content\/uploads\/2021\/12\/1.-RecordId-Variable.png\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" class=\"size-full\" style=\"border: 1px solid #A9A9A9; padding: 2px; margin: 2px; align: center;\" src=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-content\/uploads\/2021\/12\/1.-RecordId-Variable.png\" alt=\"RecordId Variable\"><\/a><\/center>\n\n\n\n<h2 class=\"wp-block-heading has-vivid-red-color has-text-color has-link-color wp-elements-3e01f18178abe59c78425bc97ca95c02\"><strong>2.<\/strong> <strong>Opportunity Stage Variable<\/strong><\/h2>\n\n\n\n<center><a href=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-content\/uploads\/2021\/12\/2.-Opportunity-Stage-Variable.png\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" class=\"size-full\" style=\"border: 1px solid #A9A9A9; padding: 2px; margin: 2px; align: center;\" src=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-content\/uploads\/2021\/12\/2.-Opportunity-Stage-Variable.png\" alt=\"Opportunity Stage Variable\"><\/a><\/center>\n\n\n\n<p>Secondly, to get opportunity records we have added \u2018<strong>Get Records\u2019<\/strong> element in flow. Further more, we assign opportunity stageName field to the \u2018<strong>Opportunitystage\u2019<\/strong> variable as shown in below image.<\/p>\n\n\n\n<h2 class=\"wp-block-heading has-vivid-red-color has-text-color has-link-color wp-elements-c943a86a85c19bb92e299ff4ca7dd462\"><strong>3. Get Opportunity Record<\/strong><\/h2>\n\n\n\n<center><a href=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-content\/uploads\/2021\/12\/3.-Get-Opportunity-Record.png\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" class=\"size-full\" style=\"border: 1px solid #A9A9A9; padding: 2px; margin: 2px; align: center;\" src=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-content\/uploads\/2021\/12\/3.-Get-Opportunity-Record.png\" alt=\"Get Opportunity Record\"><\/a><\/center>\n\n\n\n<h2 class=\"wp-block-heading has-vivid-red-color has-text-color has-link-color wp-elements-7c3df9f3229fb049ca20e86b40e2ea9d\"><strong>4. Get Opportunity Record Filter<\/strong><\/h2>\n\n\n\n<center><a href=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-content\/uploads\/2021\/12\/4.-Get-Opportunity-Record-Filter.png\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" class=\"size-full\" style=\"border: 1px solid #A9A9A9; padding: 2px; margin: 2px; align: center;\" src=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-content\/uploads\/2021\/12\/4.-Get-Opportunity-Record-Filter.png\" alt=\"Get Opportunity Record Filter\"><\/a><\/center>\n<font size=\"2\"><center><i>Get Opportunity Record Filter<\/i><\/center><\/font>\n\n\n\n<p>For instance, to call flow from apex class, create an instance of an Interview object by using \u2018<strong>Flow.Interview.flowName\u2019<\/strong>. It uses start() method to execute your flow.<\/p>\n\n\n\n<h2 class=\"wp-block-heading has-vivid-red-color has-text-color has-link-color wp-elements-d812dde545b576f973fe903ed074f338\"><strong>5. Lightning Flow<\/strong><\/h2>\n\n\n\n<center><a href=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-content\/uploads\/2021\/12\/5.-Lightning-Flow.png\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" class=\"size-full\" style=\"border: 1px solid #A9A9A9; padding: 2px; margin: 2px; align: center;\" src=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-content\/uploads\/2021\/12\/5.-Lightning-Flow.png\" alt=\"Lightning Flow\"><\/a><\/center>\n\n\n\n<p>For example,&nbsp;refering to the apex class code below, you will notice we have created the instance of Interview object and passes opportunity Id as a parameter.<\/p>\n\n\n\n<pre class=\"wp-block-code has-background\" style=\"background-color:#e6e6e6\"><code>\/\/Create parameter\nMap&lt;String, Object&gt; Params = new Map&lt;String, Object&gt;();\nParams.put('recordId','006p000000Aal2EAAR');\n\n\/\/create instance of Interview\nFlow.Interview.GetOpprtunityStageName stage = new Flow.Interview.GetOpprtunityStageName(Params);\n\n\/\/Invoke start method\nstage.start();\n\n\/\/get value from Flow\nstring stageName=(string)stage.getvariableValue('opprtunityStage');\nsystem.debug('stageName::: '+stageName);\n<\/code><\/pre>\n\n\n\n<p>As a result, after execution of flow it will return the stage of that particular opportunity which id we have passed as a parameter. kindly refer to the below image.<\/p>\n\n\n\n<p class=\"has-vivid-red-color has-text-color has-link-color wp-elements-b45944c594b1554c76aae8b0674f094f\"><strong>6.<\/strong> <strong>Debug Result<\/strong><\/p>\n\n\n\n<center><a href=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-content\/uploads\/2021\/12\/6.-Debug-Result.png\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" class=\"size-full\" style=\"border: 1px solid #A9A9A9; padding: 2px; margin: 2px; align: center;\" src=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-content\/uploads\/2021\/12\/6.-Debug-Result.png\" alt=\"Debug Result\"><\/a><\/center>\n\n\n\n<p>In conclusion,&nbsp;using the steps above you can call lightning auto launched flow from the apex code.<\/p>\n\n\n\n<p>We hope that you find this blog helpful, if you still have queries, don\u2019t hesitate to contact us at&nbsp;<a rel=\"noreferrer noopener\" href=\"mailto:salesforce@greytrix.com\" target=\"_blank\">salesforce@greytrix.com<\/a>.<\/p>\n\n\n\n<p style=\"text-align: justify\"><b>About Us<\/b><\/br>\n<p><a href=\"https:\/\/www.greytrix.com\/\">Greytrix<\/a> \u2013 a globally recognized and one of the oldest Sage Development Partner and a Salesforce Product development partner offers a wide variety of integration products and services to the end users as well as to the Partners and Sage PSG across the globe. We offer Consultation, Configuration, Training and support services in out-of-the-box functionality as well as customizations to incorporate custom business rules and functionalities that require apex code incorporation into the Salesforce platform.<br><br> Greytrix has some unique solutions for Cloud CRM such as <a href=\"\">Salesforce Sage integration<\/a> for <a href=\"https:\/\/www.greytrix.com\/sage-x3-erp\/integration\/\">Sage X3<\/a>, <a href=\"https:\/\/www.greytrix.com\/salesforce-cloud-services\/sage-100-integration\/\">Sage 100<\/a> and <a href=\"https:\/\/www.greytrix.com\/salesforce-cloud-services\/sage-300-integration\/\">Sage 300 (Sage Accpac)<\/a>. We also offer best-in-class Cloud CRM <a href=\"https:\/\/www.greytrix.com\/salesforce-cloud-services\/crm-development\/\">Salesforce customization and development services<\/a> along with services such as Salesforce <a href=\"https:\/\/www.greytrix.com\/salesforce-cloud-services\/data-migration-support\/\">Data Migration<\/a>, <a href=\"https:\/\/www.greytrix.com\/salesforce-cloud-services\/crm-development\/\">Integrated App development<\/a>, Custom App development and Technical Support business partners and end users. Salesforce Cloud CRM integration offered by Greytrix works with Lightning web components and supports standard opportunity workflow. Greytrix GUMU&#x2122; integration for Sage ERP \u2013 Salesforce is a 5-star rated app listed on <a href=\"https:\/\/appexchange.salesforce.com\/appxListingDetail?listingId=a0N30000000psM5EAI\" target=\"_blank\" rel=\"noopener\">Salesforce AppExchange<\/a>.<br> The GUMU&#x2122; Cloud framework by Greytrix forms the backbone of cloud integrations that are managed in real-time for processing and execution of application programs at the click of a button.<br><br> For more information on our Salesforce products and services, contact us at <a href=\"mailto:salesforce@greytrix.com\">salesforce@greytrix.com<\/a>. We will be glad to assist you.<\/p>\n\n\n\n<p><strong>Related Posts<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/2021\/11\/18\/how-to-create-and-implement-custom-salesforce-notification-using-process-b\">How to Create (and Implement) Custom Salesforce Notification using Process Builder<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/2021\/10\/06\/how-to-use-email-template-in-standard-salesforce-flow\/\">How to use Email Template in Standard Salesforce Flow<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>We will talk about how to call a Lightning Auto-launched flow from the Apex class in this blog post. The flow in Salesforce can be launched without user Interaction such as from a process builder or the apex code. So here we are creating a auto launched flow and call it through the apex code.\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/2024\/02\/06\/how-to-invoke-lightning-auto-launched-flow-from-the-apex-class\/\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":2,"featured_media":9438,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[13,859,1787,16,1222,1785,1786,1221,1784,1224,678,1223,1225,206,208,1220,367,677,651],"class_list":["post-6439","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-salesforce-srv","tag-apex","tag-apex-class","tag-apex-class-in-salesforce","tag-apex-in-salesforce","tag-auto-launched-flow","tag-call-apex-from-flow","tag-call-flow-from-apex","tag-call-lightning-flow-from-apex","tag-call-screen-flow-from-apex","tag-flow","tag-gumulightninginterface","tag-interview-object","tag-launch-flow-from-apex","tag-lightning","tag-lightning-component","tag-lightning-flow","tag-salesforce","tag-salesforce-lightning","tag-salesforce-lightning-component"],"_links":{"self":[{"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/posts\/6439","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/comments?post=6439"}],"version-history":[{"count":9,"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/posts\/6439\/revisions"}],"predecessor-version":[{"id":9743,"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/posts\/6439\/revisions\/9743"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/media\/9438"}],"wp:attachment":[{"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/media?parent=6439"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/categories?post=6439"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/tags?post=6439"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}