Build a Record Preview Page in Salesforce Screen Flow Using LWC

When we create the records using screen flow in Salesforce, there is no option to preview the provided details. Without the preview, there is a chance that the record is getting saved with the wrong information.

As a solution for this issue, I added a preview screen that displays the entered details before creating the record. In this, the user can preview and correct the details.

In this article, we will learn about how to build a record preview page in Salesforce screen flow using LWC. In this context, I will explain how to display an LWC component in the screen flow and pass values to its variables.

Build a Record Preview Pane in Salesforce Screen Flow Using LWC

In Salesforce, when we create the records from the screen flow by providing values to the screen components, the record is directly saved as we hit the save button.

Next, we will add a preview screen to the screen flow, allowing us to validate details and edit any incorrect information.

We will achieve this using screen flow and LWC (Lightning Web Component) in Salesforce.

Create an LWC (Lightning Web Component) to Create a Preview Page in Salesforce

First, create an LWC component and provide a name, which will make the following files:

I have provided recordPreview as the LWC component name.

  1. recordPreview.html (Page Design)
  2. recordPreview.js (Retrieve Data from Salesforce Org)
  3. recordPreview.js-meta.xml (Control Variables and Exposure)

1. recordPreview.html

In the HTML file below, we designed the page to display a preview after the user provides the value to register for an event.

In this process, we added all the fields we want to use when creating the record.

<template>
  <lightning-card title="Registration Preview">
    <div class="slds-p-around_medium">
      <p><strong>Name:</strong> {name}</p>
      <p><strong>Email:</strong> {email}</p>
      <p><strong>Phone:</strong> {phone}</p>
      <p><strong>Status:</strong> {status}</p>
      <p><strong>Registration Date:</strong> {registrationDate}</p>
      <p><strong>Event Name:</strong> {eventName}</p>
      <p><strong>Session Time:</strong> {sessionTime}</p>
    </div>
  </lightning-card>
</template>

2. recordPreview.js

Next, we use JavaScript to retrieve the values from the Salesforce org. We use @api in the JavaScript (.js) file of an LWC to expose properties and methods publicly.

import { LightningElement, api } from 'lwc';

export default class RecordPreviewFlow extends LightningElement {
  @api name;
  @api email;
  @api phone;
  @api status;
  @api registrationDate;
  @api eventName;
  @api sessionTime;
}

3. recordPreview.js-meta.xml

Now, after deploying the LWC component to the Salesforce org, we need to add a target where we want to add this component in Salesforce, whether it is a record page, homepage, app page, or Flows.

<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
  <apiVersion>59.0</apiVersion>
  <isExposed>true</isExposed>
  <targets>
    <target>lightning__FlowScreen</target>
  </targets>
  <targetConfigs>
    <targetConfig targets="lightning__FlowScreen">
      <property name="name" type="String" label="Name" />
      <property name="email" type="String" label="Email" />
      <property name="phone" type="String" label="Phone" />
      <property name="status" type="String" label="Status" />
      <property name="registrationDate" type="String" label="Registration Date" />
      <property name="eventName" type="String" label="Event Name" />
      <property name="sessionTime" type="String" label="Sess