ABSYZ ABSYZ

  • Home

    Home

  • About us

    Who We Are

  • Our Expertise

    What we Do

  • Our Approach

    How We Do It

  • Products

    What We Made

  • Industries

    Who We Do It For

  • Clients

    Whom We Did It For.

  • Article & Blogs

    What Experts Think

  • Careers

    Join The Team

  • Get In Touch

    Let’s Get Started

ABSYZ

Lightning Components As Flow Screens

Home / Article & Blogs / Salesforce / Lightning / Lightning Components As Flow Screens
By Abhishek Raj inLightning, Salesforce, Visual Workflow

One of the biggest feature announcement of Spring ’18 is Flow Components. World of Lightning Components have reached lightning flow.We can directly drag the Lightning component written by someone else to our flow screen, and thus it dramatically improves the range of things we could do using flow the screen. We just need to implement the interface in our lightning component to use it into flow screen.

Configure Components for Flow Screens

  • Make your custom Lightning components available to flow screens in the Cloud Flow Designer by implementing the lightning:availableForFlowScreens interface.
  • Next, add a design resource to your component bundle.
    A design resource describes the design-time behavior of a Lightning component—information that visual tools need to allow adding the component to a page or app.
    It contains attributes that are available for admins to edit in the Cloud Flow Designer.
  • Header and Footer is optional. If we want custom header or footer we can uncheck the check box.

Screenshot (12)

lightning:availableForFlowScreens

This interface is supported only in Lightning run time.
This interface is a marker interface. A marker interface signals the component’s container to add the interface’s behavior to the component.
You don’t need to implement methods or attributes in your component. Instead, you just add the interface name to the component’s implements attribute.Few other interface like “flexipage:availableForAllPageTypes, flexipage:availableForRecordHome” won’t work when we use our component as a flow screen.

Let’s dive into a demo and see our components in action

  • In this demo we have two components, first to create Contact and second to create Opportunity. Flow component is added to  Account record detail page. To use these components in the flow screen first we need to include lightning:availableForFlowScreens interface. In this demo, both the components are in separate screen as shown in the figure below.

Screenshot (35)

  • We pass the record Id of Account from the flow into our design attribute of lightning component by using an Input/Output variable named “recordId”. By naming a variable as recordId, it automatically stores the Id of the record in which the flow component is kept.

Screenshot (36)

  • Contact form has standard footer to navigate to the Opportunity form while Opportunity form has customized footer.

In this demo, record is created using powerful functionality of Lightning Data Service(LDS) which reduces our task to make any apex call or use standard record create screen of the flow for creating new record. The controller method is called using button on the customized footer of the opportunity flow screen.

Screenshot (39)Screenshot (41)

The details filled in the form can be retrieved by setting a local Input/Output flow variable to our design attribute in Lightning component. Setting up the design attribute is shown below.

Lightning Component: CreateContact.cmp

[sourcecode language=”html”]
<aura:component implements=”lightning:availableForFlowScreens, force:appHostable, force:hasRecordId, force:lightningQuickAction” access=”global”>
<aura:attribute name=”con” type=”Contact” default=”{‘LastName’:”,’Phone’:”,’Email’:”}” />
<aura:attribute name=”recordError” type=”String” />
<aura:attribute name=”newrecord” type=”Object” />
<aura:attribute name=”targetR” type=”String” />
<aura:handler name=”change” value=”{!v.con}” action=”{!c.handleChange}” />
<aura:attribute name=”recordId” type=”String” />
<aura:handler name=”init” value=”{!this}” action=”{!c.doInit}” />

<force:recordData aura:id=”ContactDetail” layoutType=”FULL” targetRecord=”{!v.newrecord}” targetFields=”{!v.con}” targetError=”{!v.recordError}” />
<div class=”slds-text-align–left”>
<h3 class=”slds-section-title–divider”>Contact Form</h3><br/>
</div>
<form class=”slds-form–stacked”>

<lightning:input aura:id=”Contactform” label=”Name” name=”lastname” value=”{!v.con.LastName}” />

<lightning:input type=”email” aura:id=”Contactform” label=”Email” name=”contactemail” value=”{!v.con.Email}” />
<lightning:input type=”Tel” aura:id=”Contactform” label=”Phone” name=”phone” value=”{!v.con.Phone}” pattern=”[0-9]{3}-[0-9]{3}-[0-9]{4}” />
</form>
</aura:component>
[/sourcecode]

JavaScript Controller: CreateContactController.js

[sourcecode language=”java”]
({
doInit: function(component, event, helper) {
// Prepare a new record from template
component.find(“ContactDetail”).getNewRecord(
“Contact”, // sObject type (objectApiName)
null, // recordTypeId
false, // skip cache?
$A.getCallback(function() {
var rec = component.get(“v.newrecord”);
var error = component.get(“v.recordError”);
if(error || (rec === null)) {
return;
}
})
);
},

handleChange:function(component,event){
component.set(“v.con.AccountId”, component.get(“v.recordId”));
component.set(“v.targetR”,JSON.stringify(component.get(“v.newrecord”)));
},

})
[/sourcecode]

Lightning Design:  CreateContact.design

[sourcecode language=”html”]
<design:component >
<design:attribute name=”con” label=”Contact Record”/>
<design:attribute name=”recordId” label=”Account RecordId”/>
<design:attribute name=”targetR” label=”Target Record”/>
</design:component>
[/sourcecode]

Lightning Component:  CreateOpportunity.cmp

[sourcecode language=”html”]
<aura:component implements=”lightning:availableForFlowScreens, force:appHostable, force:hasRecordId, force:lightningQuickAction” access=”global”>
<aura:attribute name=”opp” type=”Opportunity” default=”{‘sobjectType’ :’Opportunity’,’Name’:”,’Amount’:”,’StageName’:’Needs Analysis’,’CurrencyIsoCode’:’INR’}” />
<aura:attribute name=”opprecord” type=”Object” />
<aura:attribute name=”newrecord” type=”Object” />
<aura:attribute name=”showOpp” type=”Boolean” />
<aura:attribute name=”getTarget” type=”String” />
<aura:attribute name=”recordError” type=”String” />
<aura:attribute name=”con” type=”Contact” default=”{‘LastName’:”,’Phone’:”,’Email’:”}” />
<aura:attribute name=”cont” type=”Contact” default=”{‘LastName’:”,’Phone’:”,’Email’:”}” />
<aura:attribute name=”recordId” type=”String” />
<aura:handler name=”init” value=”{!this}” action=”{!c.doInit}” />

<force:recordData aura:id=”OppDetail” layoutType=”FULL” targetRecord=”{!v.opprecord}” targetFields=”{!v.opp}” targetError=”{!v.recordError}” />
<force:recordData aura:id=”ContactDetail” layoutType=”FULL” targetRecord=”{!v.newrecord}” targetFields=”{!v.cont}” targetError=”{!v.recordError}” />
<div class=”slds-text-align–left”>
<h3 class=”slds-section-title–divider”>Opportunity Form</h3><br/>
</div>
<form class=”slds-form–stacked”>
<lightning:input aura:id=”Opptform” label=”Name” name=”name” value=”{!v.opp.Name}” />

<label class=”slds-form-element__label” for=”select-01″>Currency</label>
<ui:inputSelect class=”single” aura:id=”InputSelectCurrency” change=”{!c.onSingleSelectCurrency}”>
<ui:inputSelectOption text=”USD” />
<ui:inputSelectOption text=”INR” value=”true” />
</ui:inputSelect>
<ui:inputCurrency aura:id=”Opptform” label=”Amount” value=”{!v.opp.Amount}” />

<label class=”slds-form-element__label” for=”single”>Stage</label>
<ui:inputSelect class=”single” aura:id=”InputSelectSingle” change=”{!c.onSingleSelectChange}”>
<ui:inputSelectOption text=”Any” />
<ui:inputSelectOption text=”Open” value=”true” />
<ui:inputSelectOption text=”Closed” />
<ui:inputSelectOption text=”Closed Won” />
<ui:inputSelectOption text=”Prospecting” />
<ui:inputSelectOption text=”Qualification” />
<ui:inputSelectOption text=”Needs Analysis” />
<ui:inputSelectOption text=”Closed Lost” />
</ui:inputSelect>
<ui:inputDate aura:id=”Opptform” label=”Closing Date” value=”{!v.opp.CloseDate}” displayDatePicker=”true” /><br/>
</form>
<div class=”slds-modal__footer”>
<lightning:button label=”Previous” onclick=”{!c.cancel}” class=”slds-button_brand” />
<lightning:button label=”Finish” onclick=”{!c.handleSaveContact}” class=”slds-button_brand” />
</div>

</aura:component>
[/sourcecode]

Javascript Controller:  CreateOpportunityController.js

[sourcecode language=”java”]
({
doInit: function(component, event, helper) {
component.find(“OppDetail”).getNewRecord(
“Opportunity”, // sObject type (objectApiName)
null, // recordTypeId
false, // skip cache?
$A.getCallback(function() {
var rec = component.get(“v.opprecord”);
var error = component.get(“v.recordError”);
if (error || (rec === null)) {
return;
}
})
);
component.set(“v.newrecord”, JSON.parse(component.get(“v.getTarget”)));
component.find(“ContactDetail”).getNewRecord(
“Contact”, // sObject type (objectApiName)
null, // recordTypeId
false, // skip cache?
$A.getCallback(function() {
var rec = component.get(“v.newrecord”);
var error = component.get(“v.recordError”);
if (error || (rec === null)) {
return;
}
})
);
component.set(“v.cont”, component.get(“v.con”));
component.set(“v.newrecord.AccountId.value”, component.get(“v.recordId”));
},
onSingleSelectChange: function(component, event) {
var a = component.find(“InputSelectSingle”).get(“v.value”);
component.set(“v.opp.StageName”, a);
},
onSingleSelectCurrency: function(component, event) {
var a = component.find(“InputSelectCurrency”).get(“v.value”);
component.set(“v.opp.CurrencyIsoCode”, a);
},

handleSaveContact: function(component, event, helper) {
var flag = false;
component.set(“v.newrecord.AccountId.value”, component.get(“v.recordId”));
component.set(“v.newrecord”, JSON.parse(component.get(“v.getTarget”))); //
component.set(“v.cont”, component.get(“v.con”));
component.set(“v.cont.AccountId”, component.get(“v.recordId”));

component.set(“v.opp.AccountId”, component.get(“v.recordId”));
component.find(“ContactDetail”).saveRecord(function(saveResult) {
alert(JSON.stringify(saveResult.state));
if (saveResult.state === “SUCCESS” || saveResult.state === “DRAFT”) {

flag = true;

} else if (saveResult.state === “INCOMPLETE”) {
// handle the incomplete state
} else if (saveResult.state === “ERROR”) {
// handle the error state
} else {}
});

component.find(“OppDetail”).saveRecord(function(saveOpResult) {
if ((saveOpResult.state === “SUCCESS” || saveOpResult.state === “DRAFT”) && flag == true) {
// record is saved successfully
var resultsToast = $A.get(“e.force:showToast”);
resultsToast.setParams({
“title”: “Saved”,
“message”: “New Contact and Opportunity is created.”
});
resultsToast.fire();
$A.get(“e.force:refreshView”).fire();
var navEvt = $A.get(“e.force:navigateToSObject”);
navEvt.setParams({
“recordId”: component.get(“v.recordId”)
});
navEvt.fire();

} else if (saveOpResult.state === “INCOMPLETE”) {
// handle the incomplete state
} else if (saveOpResult.state === “ERROR”) {
// handle the error state
} else {}
});
},

cancel: function(component, event) {
$A.get(“e.force:refreshView”).fire();
var navEvt = $A.get(“e.force:navigateToSObject”);
navEvt.setParams({
“recordId”: component.get(“v.recordId”)
});
navEvt.fire();

}
})
[/sourcecode]

Lightning Design:  CreateOpportunity.design

[sourcecode language=”html”]
<design:component >
<design:attribute name=”con” label=”Contact Record”/>
<design:attribute name=”opp” label=”Opportunity Record”/>
<design:attribute name=”recordId” label=”Account RecordId”/>
<design:attribute name=”getTarget” label=”Target Record”/>
</design:component>
[/sourcecode]

 

Note: This demo is just to make us familiar with the new release in the flow components. The above functionality could have been achieved using “Record Create” screen in flow or using lightning forms instead of using Lightning Data Service.

 

Lightning component in flowLightning components as flow screenLightning Flow
103
Like this post
10 Posts
Abhishek Raj

Search Posts

Archives

Categories

Recent posts

BioAsia 2023 in Hyderabad: An Annual International Event

BioAsia 2023 in Hyderabad: An Annual International Event

The Role Of Marketing in Small & Medium Enterprises

The Role Of Marketing in Small & Medium Enterprises

Salesforce For Retail: How Salesforce CRM Can Help Retailers

Salesforce For Retail: How Salesforce CRM Can Help Retailers

What is ChatGPT & How Does It Work?

What is ChatGPT & How Does It Work?

What Is Graphic Design? (Executive Summary 2023)

What Is Graphic Design? (Executive Summary 2023)

  • Previous PostEinstein Intent and Einstein Sentiment Analysis on Facebook Posts
  • Next PostMockaroo - An easy way to generate millions of test data

Related Posts

Salesforce For Retail: How Salesforce CRM Can Help Retailers
Salesforce

Salesforce For Retail: How Salesforce CRM Can Help Retailers

Introduction To Copado Devops Tool
Salesforce

Introduction To Copado Devops Tool

What is Salesforce Code Builder?
Salesforce

What is Salesforce Code Builder?

Automation in Healthcare And Its Benefits
Health Cloud Salesforce

Automation in Healthcare And Its Benefits

Leave a Reply (Cancel reply)

Your email address will not be published. Required fields are marked *

*
*

ABSYZ Logo

INDIA | USA | UAE

  • About us
  • Article & Blogs
  • Careers
  • Get In Touch
  • Our Expertise
  • Our Approach
  • Products
  • Industries
  • Clients
  • White Papers

Copyright ©2022 Absyz Inc. All Rights Reserved.

youngsoft
Copy
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “ACCEPT ALL”, you consent to the use of ALL the cookies. However, you may visit "Cookie Settings" to provide a controlled consent. Privacy Policy
Cookie SettingsREJECT ALLACCEPT ALL
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled

Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.

CookieDurationDescription
cookielawinfo-checkbox-analytics11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional11 monthsThe cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy11 monthsThe cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.

Functional

Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.

Performance

Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.

Analytics

Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.

Advertisement

Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.

Others

Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.

SAVE & ACCEPT