Salesforce Genie

Salesforce Genie

Salesforce Genie is a revolutionary app that helps you find the right customers and automate data collection so that you can focus on what matters most: selling.

Genie creates a single, comprehensive view of each customer by analyzing all the data about them coming from any source.




Let Salesforce Genie recommend customers to you based on what they have in common with other people that worked well together

Genie can search through your Salesforce database for any information—including name, email address, company name and other fields. For even more powerful searches, combine multiple filters—for instance, if you want to find all of your U.S.-based customers who've recently bought from your company and have "Marketing" in their job title.Genie will automatically find the best matches for you! Suppose it doesn't have enough information about a customer's profile (like an email address). In that case, it will use the details that are available to suggest potential matches based on their industry and region—and we'll keep doing this until we uncover their full profile information.

With Genie, it's easy for you to find multiple experts on a given account so that everyone can access relevant information at all times.

Gauge a customer’s potential to grow and win more business with less effort.

Salesforce Genie helps you find the right customers to talk with and strike deals with. It uses a proprietary process that combines demographic data, industry expertise—and other factors like behavioral patterns—to determine how likely someone is to buy what your company offers.

Cutting through the clutter of your target market and focusing on customers who are most likely to buy from you will enable you to spend more time marketing products or services that are viable for your business. Use the Customer Profile to identify and contact experts in your company who have previously worked with specific customers.

Salesforce Genie uses artificial intelligence to identify the best person to talk with about a customer. You can use Salesforce Genie to find people inside or outside your company who are willing to help.For example, let’s say you’re trying to learn more about how a customer uses Sales Cloud, but they have only been using it for a few months. You could type in “Sales Cloud beginner” into Salesforce Genie and get back all of the relevant information related to that topic.

View all of a customer’s online interactions, and publish content to multiple channels from one place.

Customer journey mapping

You can see how each of your customers interacts with you online, as well as across all of their devices, and use that information to tailor the experience for each one. You can track your customers’ individual journeys, identify micro-moments, and use those insights to personalize their experiences across all of their digital touchpoints.

Social media monitoring

Monitoring social media accounts gives you insight into what your competitors are doing and lets you stay ahead of them when it comes to developing new marketing campaigns or products.

Social media publishing

Whether it’s a Facebook post or tweet, a LinkedIn update, or a Pinterest pin, managing this content has always been a time-consuming process for marketers who want to make sure their message reaches as many people as possible. With Salesforce Genie you can schedule posts for yourself or others out into the future so that you don’t have to worry about forgetting about them when the time comes around! Social media advertising A huge amount of effort goes into creating awesome content but if no one sees it then there’s no point right? Luckily with Genie, we’ve got some great integration options that allow us to measure how well our ads perform by tracking clicks through directly back into Salesforce where they’re stored alongside any other info we might need such as ad spend etcetera! Web analytics If there was ever an easy way for companies big or small (or even medium size) then I think everyone should take advantage since almost everyone uses it nowadays anyway 🙂

Every piece of data and history you need is right there on the screen.

As a Salesforce administrator, you are responsible for managing the data and history of your organization’s users. The Genie tool makes this easy by displaying all that information on one screen in real time.

You can also use Genie to make decisions about how your organization’s data is displayed on the screen. For example, if there are too many fields or columns displayed at once, you can hide them temporarily with a single click.

Salesforce Genie can turn your data into magic.

It can be difficult to manage all aspects of a business. But customers deserve the best service possible—so Salesforce Genie helps you focus on selling rather than paperwork so that you can provide exceptional customer support.

Salesforce Summer’22 Release Date and Preview Sandbox

Salesforce Summer’22 Release Date and Preview Sandbox

With the Salesforce Summer’22 release right around the corner, here are some key dates as well as important information salesforce made available to the general audience.

Sandbox Preview Summer’22

From May, 7th 2022, Salesforce will start releasing Summer’22 updates to preview sandboxes. Not all sandboxes are preview sandboxes. You can use this Heroku app provided by salesforce to check if your sandbox is a preview sandbox.

You can take the below actions to make nonpreview sandbox to preview sandbox or vice-versa.

Make Nonpreview sandbox to preview sandbox

If your sandbox isn’t in the preview instance and you like it to be your preview sandbox, refresh your sandbox before May, 6th 2022

Make Preview sandbox to Nonpreview

Refresh your preview sandbox after May 7th, 2022 to make your Summer’22 preview sandbox roll back to the Spring’22 release.

Pre-release org Signup

Salesforce prerelease org is a great way to familiarize yourself with new releases. This allows you to try new features Hands-on. Sign-up will be allowed from April 16th, 2022. Click here to signup on or after December 16th if you like to try the latest released features.

Summer’22 Release notes

Click here to check if release notes are available on salesforce. If you see a page not found error, it’s due to release notes are not available yet.

Key dates

The Release Date for Summer ’22 will depend on your instance of Salesforce, but the main release weekends are on…

  • May 21st, 2022
  • June 4th, 2022
  • June 11th, 2022

Visit this link to review previous salesforce releases

  • Salesforce Spring’22 Key dates + Preview Information

    Salesforce Spring’22 Key dates + Preview Information

    With the Salesforce spring’22 release right around the corner, here are some key dates as well as important information salesforce made available to the general audience. Sandbox Preview Spring’22 From January, 7th 2022, Salesforce will start releasing Spring’22 updates to preview sandboxes. Not all sandboxes are preview sandboxes. You can use this Heroku app provided…


  • Choose the Salesforce Automation tool wisely

    With salesforce making Salesforce Flow stronger and stronger every release, It’s important to make an informed decision on which Automation tool will be most effective for the solution you are designing for the business requirement. In seasonal release of Spring 2020, Salesforce releases before-save flow triggers followed by after-save flow triggers in Summer 2020 release.…


  • Salesforce Spring’21 Release

    Salesforce Spring’21 Release

    It’s that time of the year again. Salesforce announced their latest salesforce release – Spring’21 Release. As always this release is also full of exciting new features and functionalities. Lightning Flow which is now called Salesforce Flow has a lot of new enhancements and functionalities. Let’s dive straight into key information about this release. Pre-release…


  • Salesforce Flow – Spring’21 Enhancements

    Salesforce Flow – Spring’21 Enhancements

    Spring’21 release is around the corner. Let’s review new features and enhancements Spring’21 brings to the Salesforce Admin, Developer’s and Consultants. Signup for Spring’21 Prerelease org to try your hands on the new flow features mentioned below before it even releases to the Sandbox. Review my spring’21 release post here, to get more information about…


  • Lightning Component for Salesforce Admin

    Lightning Component for Salesforce Admin

    The enterprises have much admired the low code approach for customization needs for any customization within the Salesforce. And one of the main reasons behind Salesforce becoming an industry leader. As a developer myself, we tend to jump on a custom solution for any business requirement. Salesforce recommends Click, Not code approach as a best…


  • Salesforce Genie

    Salesforce Genie is a revolutionary app that helps you find the right customers and automate data collection so that you can focus on what matters most: selling. Let Salesforce Genie recommend customers to you based on what they have in common with other people that worked well together Genie can search through your Salesforce database…


  • Salesforce Summer’22 Release Date and Preview Sandbox

    Salesforce Summer’22 Release Date and Preview Sandbox

    With the Salesforce Summer’22 release right around the corner, here are some key dates as well as important information salesforce made available to the general audience. Sandbox Preview Summer’22 From May, 7th 2022, Salesforce will start releasing Summer’22 updates to preview sandboxes. Not all sandboxes are preview sandboxes. You can use this Heroku app provided…


  • Migrate Workflows to Flow using Migrate Flow Tool

    Migrate Workflows to Flow using Migrate Flow Tool

    Migrate from Workflow rules to flows using Salesforce Migrate to flows tool (beta)


Migrate Workflows to Flow using Migrate Flow Tool

Migrate Workflows to Flow using Migrate Flow Tool

Salesforce in the spring’22 release provided a very robust tool that allows organizations to seamlessly migrate workflow rules to flows. It’s currently in beta version so has certain limitations, however, it’s not a bad idea to try your hands on this new tool. Watch this quick video to learn about what type of workflows you can currently migrate using this tool.

For Spring’22 updates and enhancements related to flow visit this page. For information regarding key dates and sandbox previews visit this page.

Spring’22 Salesforce Flow Enhancements

Spring’22 Salesforce Flow Enhancements

Salesforce released the Spring’22 release notes a couple of weeks ago. As we have observed in the last few releases, this release will also bring a ton of new exciting updates to Salesforce Flows. Here are some of my favorite salesforce flow features in this release Watch the below two quick videos or read the summary in this article.

Collection Filter

With this brand new out-of-the-box flow component, you will now be able to specify criteria when using the get records component or be able to further filter your collection using this collection filter. Using a collection filter will also allow you to avoid running into the ‘Iteration Limit Exceeded’ flow error as it opens up the governor limit to handle a larger set of records. For more information or demo look at the first video or click here.

Salesforce Flow Collection Filter Demo
Salesforce Flow Collection Filter Demo

Flow Trigger Explorer

If I have to select only one favorite feature of this entire release, it would be Flow Trigger Explorer. This provides Admins and Developers a quick glance at what all triggered flows exist for a particular object so that they can decide which one to pick for the new user requirements. Like Apex trigger, Record trigger flows also consume a great amount of CPU time and can get difficult to maintain at times if your org has many record triggered flows. But with this new tool provided by salesforce, it would be lot easier to make decisions and avoid creating multiple triggers on the same object. Take a look at this demo for a quick overview of this new tool by salesforce.

Flow trigger explorer tool for Salesforce flow
Flow trigger explorer tool for Salesforce flow

Workflow to Flow Migration tool

As promised by salesforce during the Winter’22 release, Salesforce now has provided a Pilot tool that allows organizations to migrate workflow rules to Salesforce Flow. This is very helpful for the orgs with many workflow rules, as salesforce announced that they deprecate Workflow rules as well as Process builders in near future.

Salesforce Workflow to flow migration tool
Salesforce Workflow to flow migration tool

Control order of execution for the triggered flows

With the Spring’22 release, Salesforce will allow you to define the order of execution for the triggered flow. You will be able to put numeric value flows on the same object and trigger. Some of the key points to keep in mind.

  • Flows with the same trigger (before- or after-save) on the same object with trigger order values from 1 to 1,000 run in ascending
    order (1, 2, 3, and so on). Multiple flows with the same trigger order value run in alphabetical order based on the flows’ API nam
  • Flows without trigger order values run next and in the order of their created dates. Flows in Winter ’22 and before run and continue
    to run in this order, unless you define a trigger order value for them.
  • Flows with trigger order values from 1,001 to 2,000 run next and in ascending order. Any ties are settled using the flows’ API names

Salesforce announced that their team is working on marrying this feature with salesforce flow explorer tool as shown above for drag and drop reordering ability.

Ability to define flow order of execution in salesforce flow
Ability to define flow order of execution in salesforce flow
Salesforce flow Navigate user to created record

Salesforce flow Navigate user to created record

Anyone who has worked on Screen flow specifically for cross object flows knows that Salesforce default functionality does not redirect users from flow to the created or updated record. Therefore the user will require to manually search for that created/updated record and look for that created record to view the details. This is not the ideal user experience that your user would want especially in fast-moving environments. It can impact your user’s productivity as well as increase the probability of human errors.

In this tutorial, we will look at how you can write a very simple lightning component and reuse that for all flows in your org to redirect the user to the record page after they finish the flow. No apex class/controller is used for this component so no test class is required either.

Let’s start with creating a Simple cross object flow first as shown below

Cross object Screen flow

Get Account Record

Add following fields on the screen component

Subject
Name

Add Create record component

Add field value within component as shown in the screen shot below

Create new lightning component from developer console

Create New Lightning Component from developer console
Add Lightning Component name as well as select all check boxes in the above screen since we will be using this component in multiple areas.

Add following code to your component

Make sure to include ” lightning:availableForFlowScreens ” class as implements (Highlighted in the screenshot below)to make this component available for flow.

Component

<aura:component implements="lightning:availableForFlowScreens" access="global" >
<aura:attribute name="recId" type="String" />
<aura:handler name="init" value="{!this}" action="{!c.init}" />
</aura:component>

Controller

({
init : function(component, event, helper) {
$A.get("e.force:navigateToSObject").setParams({
"recordId": component.get("v.recId"),
"slideDevName": "related"
}).fire();
}
})

Design

<design:component>
<design:attribute name="recId" label="Id of the record" />
</design:component>

Modify screen flow to include flow redirect component

Make following changes to the previously created flow to include this lightning component and navigate user to the created record

1.Modify “Create record” on flow to store record id of newly created case

Create new text variable called “NewCaseId” and check the checkbox to make that available for output

2. Add new Screen component on the flow

Insert new screen component after create record on the flow. And pass NewCaseId to the lightning component for the redirect as shown in the screenshot below

3. Save and Activate the Flow

User will now be automatically redirected/Navigated to the created record after flow finish creating the record.

For more Tips and tricks like this please click here or Flow Menu item. Follow my YouTube channel for more videos on this topic.

Salesforce Spring’22 Key dates + Preview Information

Salesforce Spring’22 Key dates + Preview Information

With the Salesforce spring’22 release right around the corner, here are some key dates as well as important information salesforce made available to the general audience.

Sandbox Preview Spring’22

From January, 7th 2022, Salesforce will start releasing Spring’22 updates to preview sandboxes. Not all sandboxes are preview sandboxes. You can use this Heroku app provided by salesforce to check if your sandbox is a preview sandbox.

You can take the below actions to make non preview sandbox to preview sandbox or vice-versa.

Make Non preview sandbox to preview sandbox

If your sandbox isn’t in the preview instance and you like it to be your preview sandbox, refresh your sandbox before January, 6th 2022

Make Preview sandbox to Non preview

Refresh your preview sandbox after January 7th, 2022 to make your spring’22 preview sandbox roll back to the Winter’22 release.

Pre-release org Signup

Salesforce prerelease org is a great way to familiarize yourself with new releases. This allows you to try new features Hands-on. Sign-up will be allowed from December 16th. Click here to signup on or after December 16th if you like to try the latest released features.

Keydates

Release notes are now available. Click here to review release notes from salesforce.

December 16: Sign up for a pre-release environment

December 22: Preview Release Notes are available

January 6: Sandbox cut-off date

January 7 and 8: Sandboxes upgraded

January 7: Spring ’22 Release site is live

January 14: First release weekend

February 4 to 11: Release readiness live broadcast

Previous Salesforce release

Visit this link to review previous salesforce releases

Choose the Salesforce Automation tool wisely

Choose the Salesforce Automation tool wisely

With salesforce making Salesforce Flow stronger and stronger every release, It’s important to make an informed decision on which Automation tool will be most effective for the solution you are designing for the business requirement.

In seasonal release of Spring 2020, Salesforce releases before-save flow triggers followed by after-save flow triggers in Summer 2020 release. With that Salesforce officially recommended Flow and Apex as No-code and Pro-code preferred options for record triggered automation on their platform

Let’s review which tools salesforce recommends and rational for the most appropriate automation tool on the platform for various use cases.

Before-Save Flow TriggerAfter-Save Flow TriggerAfter-Save Flow Trigger + ApexApex Triggers
Same-Record Field UpdatesAvailableNot IdealNot IdealAvailable
High-Performance Batch ProcessingAvailableNot IdealNot IdealAvailable
Cross-Object CRUDNot AvailableAvailableAvailableAvailable
Complex List ProcessingNot AvailableNot AvailableAvailableAvailable
Fire & Forget Asynchronous ProcessingNot AvailableNot AvailableAvailableAvailable
Other Asynchronous ProcessingNot AvailableNot AvailableNot AvailableAvailable
Custom Validation ErrorsNot AvailableNot AvailableNot AvailableAvailable
  • Available = should work fine, with basic considerations.
  • Not Ideal = possible, but with important and potentially limiting considerations.
  • Not Available = no plans to support in any capacity in the next twelve months.

Workflow Rule, Process Builder & Salesforce Flow

While salesforce announced that they are not discontinuing Workflow rules or Process builder anytime soon they will be deprecated flow. Therefore will no longer receive any performance, Debugging, Manageability or CI/CD improvements.

Workflow Rules:

The majority of workflow rules are known for the Same record field updates and being fast. They nevertheless cause a recursive save and will always be considerably slower and more resource-hungry than a single functionally equivalent before-save Flow trigger.

Process Builder:

Process builder in fact runs on top of flow’s runtime, However, there is a vast difference between Process Builder’s user-facing design-time model and the Flow runtime’s metadata model.  Process builder will always be less user-friendly and has a list view that doesn’t allow any filters or modification which makes it more difficult to manage process.

For this reasons, Salesforce recommends, Building with Flow where possible, and resorting to Process builder or workflow when necessary.

Compare Performance between different automation tools

This performance discussion is around the Same record field update use case. While Workflow Rules have a reputation for being fast, they nevertheless cause a recursive save and will always be considerably slower and more resource-hungry than a single functionally equivalent before-save Flow trigger.

 Before-save Flow triggers neither causes DML nor the ensuing recursive firing of the save order, while Workflow Rules do because they happen after the save.

Based on this theory, a couple of experiments were performed by salesforce to compare the processing time and CPU usage

Experiment 1: Apex Debug log duration for Single Triggered single record creation through UI by User

User’s wait time comparison for the same action (Record creation) using different automation tool (Workflow/Process Builder/ Salesforce flow)

  1. Except for the baseline org, implemented the simplest version of a trigger on Opportunity Create that would set Opportunity.NextStep = Opportunity.Amount.
  2. Enabled Apex debug logging, with all debug levels set to None except Workflow.Info and Apex Code.Debug
  3. Manually created a new Opportunity record with a populated Amount value through the UI, 25 times.
  4. Calculated the average duration of the log across the 25 transactions.
  5. Subtracted from the average duration in #4, the average duration of the log in the baseline org.

Experiment 2: 50 triggers; 50,000 records inserted via Bulk API (200 record batches); internal tooling

How about the other side of the spectrum: high-volume batch processing?

We borrowed some of our performance team’s internal environments to get a sense of how well the different trigger tools scale.

The configuration was:

  • 1 org with 50 before-save Flows on Account Create which each update Account.ShippingPostalCode
  • 1 org with 50 before-save Apex triggers on Account Create which each update Account.ShippingPostalCode
  • 1 org with 50 Workflow Rules on Account Create which each update Account.ShippingPostalCode
  • 1 org with 50 after-save Flow triggers on Account Create which each update Account.ShippingPostalCode
  • 1 org with 50 Process Builder processes on Account Create which each update Account.ShippingPostalCode

Then each Tuesday for the last 12 weeks, we uploaded 50,000 Accounts to each org through the Bulk API, with a 200-record batch size.

Fortunately, our internal environments can directly profile trigger execution time without requiring Apex debug logging or extrapolation from a baseline.

Unfortunately, our internal environments are so ill-representative of production that we’re only allowed to present the relative performance timings and not the raw performance timings.

Bar chart showing average time added to bulk record updates from most to least efficient tool.

As you ca see from the above chart, In both single-record and bulk use cases, the before-save Flow performs extremely well.

CPU Usage

CPU time reported in apex debug log is inconsistent at the moment, which salesforce reported as issue with reporting and not with measurement issue.

For example, if a Flow consumes 8s actual CPU time during runtime, then the cumulative Governor CPU time limit will be incremented by 8s. However, the Flow element-level contributions to the limit, which are displayed in the Apex debug logs, are not always properly attributed. Sometimes, CPU time that should have been attributed to a Flow element is not attributed to any element in the Flow. As a result of this misattribution, the sum of the attributed element costs will not always equal 8s; instead, they may add up to a number that is less than 8s. In this case, the difference will be unintentionally rolled into the next CPU time consumption line in the debug logs. Salesforce is planning to fix this in upcoming release.

In the meantime, a Flow’s CPU time consumption can be upper-capped by its wall clock time consumption. This is because Flows run on a single thread.

Salesforce Spring’21 Release

Salesforce Spring’21 Release

It’s that time of the year again. Salesforce announced their latest salesforce release – Spring’21 Release. As always this release is also full of exciting new features and functionalities. Lightning Flow which is now called Salesforce Flow has a lot of new enhancements and functionalities.

Let’s dive straight into key information about this release.

Pre-release org Signup

If you are like me and can’t wait till the Spring’21 release hits your sandbox, Click here to sign-up for Spring-21 prerelease org.

Spring’21 Sandbox Preview

While Spirng’21 release currently available only under the Pre-release program, It will be available to individual eligible sandbox by end of January 8th and 9th of 2021. Make sure your sandbox is part of the Preview instance by checking your instance id in the below list. If your sandbox is part of the Non-Preview instance it will ultimately get the spirng’21 release by end of day January 15 and February 5th and 12th 2021.

Instance TypeRelease Date
Preview SandboxJanuary 08th & 09th
Non-Preview SandboxFebruary 13th & 14th
ProductionJanuary 15th
February 05th & 12th
Spring’21 release date


Release Date January 08/ 09

Preview Instances: CS2, CS4, CS5, CS7, CS9, CS11, CS14, CS15, CS17, CS19, CS20, CS21, CS23, CS25, CS26, CS27, CS28, CS31, CS32, CS34, CS35, CS36, CS37, CS41, CS42, CS44, CS45, CS47, CS53, CS57, CS59, CS61, CS63, CS67, CS69, CS72, CS74, CS75, CS76, CS77, CS78, CS79, CS80, CS81, CS84, CS87, CS88, CS91, CS95, CS96, CS97, CS99, CS105, CS106, CS107, CS108, CS109, CS111, CS112, CS113, CS116, CS122, CS123, CS124, CS125, CS126, CS127, CS128, CS129, CS133, CS137, CS138, CS142, CS152, CS159, CS160, CS169, CS174, CS189, CS190, CS191, CS192, CS193, CS194, CS195, CS196, CS197, CS198, CS199, CS201, CS203, AUS2S, AUS8S, IND3S, USA3S

Release Date February 13/14

Non – Preview Instances: CS1, CS6, CS8, CS10, CS16, CS18, CS22, CS24, CS29, CS33, CS40, CS43, CS50, CS52, CS58, CS60, CS62, CS64, CS65, CS66, CS68, CS70, CS73, CS86, CS89, CS90, CS92, CS94, CS98, CS100, CS101, CS102, CS110, CS114, CS115, CS117, CS119, CS121, CS132, CS148, CS151, CS162, CS165, CS173, AUS4S, IND2S, USA2S

Switch to Sandbox Preview Instance from Non -Preview instances

If you are part of the Non-Preview sandbox list fear not, refresh your sandbox before January 7th, 2021 and Salesforce will automatically assign one of the preview instance IDs to your current Sandbox.

Follow instructions on my previous blog post to find your current sandbox instance id to determine if you are in a preview instance or non-preview instance.

Key dates for Spring’21 release

Salesforce Flow – Spring’21 Enhancements

Salesforce Flow – Spring’21 Enhancements

Spring’21 release is around the corner. Let’s review new features and enhancements Spring’21 brings to the Salesforce Admin, Developer’s and Consultants.

Signup for Spring’21 Prerelease org to try your hands on the new flow features mentioned below before it even releases to the Sandbox. Review my spring’21 release post here, to get more information about how to signup for Spring’21 prerelease org.

If you have not noticed yet, Salesforce renamed Lightning Flow to Salesforce Flow.

Spring’21 Top 5 Flow Enhancements

1) Prior Value / Old value – Record triggered Flow

This flow enhancement is my personal favorite. It was a huge drawback in flow now. Despite having multiple workarounds to access prior values each of them included working with a process builder or another automation tool to store prior value or old value in the flow variable. With Spring’21 enhancements, Prior values are available out of the box using global variable $Record__Prior.

Check the screenshot below to learn how to access the $Record_Prior global variable in record Triggered Flow.

2) Time Based / Time-Dependent Action – Record Triggered Flow

This was another major drawback that forced Admins and Developers in the past to either partially rely on other automation tools like workflow or process flow or completely prevent them from using flow due to the maintainability of the org in long term.

Schedule Paths Configuration
Flow Time Based / Time-Dependent Actions or Time-Triggered Actions

3) Multicolumn Page layout for Screen flows

Screen components within flow until now only supported a single column layout. Which was less than idle user experience for long forms. And had no other choice but to use the lightning component within the flow or completely switch to a custom approach instead of flow.

Thanks to Spring’21 release flow enhancements, Salesforce now supports multiple column layouts. Refer to the screenshot below to view how multiple column layouts operated within the flow.

Multiple column Screen layout

4) Debug Flow error email notifications more easily

For every flow failure, salesforce sends an email notification to the Org Apex exception email subscribers. Admin / Developer needed to debug the flow by going through a long chain of text to debug the flow before.

Now by simply clicking on the link within the email notification as highlighted in the below screenshot, salesforce will not only open the flow but will also highlight the node which caused it to fail.

Flow error notification

Debug Flow error notifications

5) Access Complex merge fields from loops

Now you can loop through a collection via merge fields on complex objects such as an Apex-defined variable or output from a custom action or screen component. Previously, you weren’t able to access merge fields on complex objects.

Spring '21 Salesforce Release Notes




Lightning Component for Salesforce Admin

Lightning Component for Salesforce Admin

The enterprises have much admired the low code approach for customization needs for any customization within the Salesforce. And one of the main reasons behind Salesforce becoming an industry leader.

As a developer myself, we tend to jump on a custom solution for any business requirement. Salesforce recommends Click, Not code approach as a best practice to utilize the best value of the native functionality the platform has to offer. In Salesforce, every written line of custom code will require to maintain. Any modification, regardless of how small it is, will need a developer’s engagement as Admin does not generally have the skills to modify custom-developed code.

As we all know, it isn’t a cost-effective approach to engage developers for small requirement modification. Therefore when developing a custom solution, we should always look for an opportunity to develop in a way that can be easily maintained by Admin without code knowledge.

I am not by any means trying discourage you from developing a custom code in salesforce. Instead of asking to be considerate about Admins in your team when developing any custom code.

Let’s have a look at the example of page layout in Salesforce. As we are all aware, page layouts sometimes can become very lengthy for specific needs with all fields and sections available on the page layout.

Issue with Flow screen component and field elements

Let’s say you need to load a record page within the flow screen. Although the Flow screen has components for fields and sections, it’s a lot of hassle to add each element to the screen and map it back to the appropriate field. Even after all that, you will not receive the desired result as the flow doesn’t support multiple columns in a row. Reference screenshot below to view the screen component with fields added.

This image has an empty alt attribute; its file name is image-1-1024x330.png

Developers within ourselves, when presented with such a scenario would want to jump on developing custom components to deliver the idle user experience. Not necessarily always keeping maintainability issue for small requirement changes like

  • A new required field on the page layout
  • Rearrangement of the fields and section on the page layout
  • Renaming field label

Solution using lightning component

In the example below, we will review the lightning component that can be easily modified by admin without having any coding knowledge. With little to no efforts on the component, the below code will automatically pull what is available on the page layout, including standard ad custom fields sections and labels of the fields.

Aura Component

<aura:component implements="flexipage:availableForAllPageTypes" access="global" controller="DynamicPageLayout">

    <aura:attribute name="disabled" type="Boolean" default="false" />
    <aura:attribute name="layoutSections" type="List" />
    <aura:attribute name="saved" type="Boolean" default="false" />
    <aura:attribute name="showSpinner" type="Boolean" default="true" />
    <aura:attribute name="fieldName" type="String" default="StageName" />
    
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
    <lightning:card title="">
        <aura:if isTrue="{!v.showSpinner}">
            <lightning:spinner />
        </aura:if>
        <aura:if isTrue="{!!v.saved}">
            <lightning:recordEditForm
                onload="{!c.handleLoad}"
                onsubmit="{!c.handleSubmit}"
                onsuccess="{!c.handleSuccess}"
                objectApiName="Contact">
                <lightning:messages />
                
                <aura:iteration items="{!v.layoutSections}" var="section">
                    <div class="slds-section slds-is-open">
                    	<h3 class="slds-section__title">
                            {!section.label}
                        </h3>
                        <div class="slds-section__content">
                            <lightning:layout multipleRows="{!section.totalColumns > 1 }">

                                <aura:iteration items="{!section.lstFields}" var="field">

                                    <lightning:layoutItem size="{! 12/section.totalColumns }" flexibility="auto" padding="around-small">
                                        <aura:if isTrue="{!(!field.isReadOnly)}">
                                            <lightning:inputField fieldName="{!field.fieldName}" />	
                                            <aura:set attribute="else">
                                                <lightning:outputField fieldName="{!field.fieldName}" />	 
                                            </aura:set>
                                        </aura:if>
                                    </lightning:layoutItem>

                                </aura:iteration>
                         </lightning:layout>
                        </div>
                    </div>
                </aura:iteration>
                <lightning:layout verticalAlign="center" class="x-large">
                	<lightning:layoutItem padding="around-large"> 
                        <div class="slds-m-top_medium">
                        	<lightning:button disabled="{!v.disabled}" variant="brand" type="submit" name="save" label="Save" />
                    	</div>
                    </lightning:layoutItem>   
            	</lightning:layout>
            </lightning:recordEditForm>
            <aura:set attribute="else">
                <p>Saved!</p>
            </aura:set>
        </aura:if>
    </lightning:card>
</aura:component>

Controller

({
    doInit: function( component, event, helper ) {
        var action = component.get("c.getPageLayoutFields");
		action.setCallback(this, function(response) {
        	var state = response.getState();
			if (state === "SUCCESS") {
                component.set("v.layoutSections", response.getReturnValue() );
                console.log( response.getReturnValue() );
            }
            else if (state === "INCOMPLETE") {
            }
            else if (state === "ERROR") {
                var errors = response.getError();
				console.log( errors );
            }
        });
        
        $A.enqueueAction(action);
    },
    
    
	handleSuccess : function(component, event, helper) {
        var toastEvent = $A.get("e.force:showToast");
        toastEvent.setParams({
            "title": "Success!",
            "message": "Updated",
            "type": "success"
        });
        toastEvent.fire();
        
    },
    handleLoad : function(component, event, helper) {
    	component.set("v.showSpinner", false);   
    },
    handleSubmit : function(component, event, helper) {
       
    }
})

Apex Class

public class DynamicPageLayout {
	
    @AuraEnabled 
    public static List<LayoutSection> getPageLayoutFields() {
        
        List<LayoutSection> lstSections = new List<LayoutSection>();
        
        try {
            
            List<String> componentNameList = new List<String>{'Contact-Contact Layout'};
           
            List<Metadata.Metadata> components = Metadata.Operations.retrieve(Metadata.MetadataType.Layout, componentNameList);
            Metadata.Layout contLayout = (Metadata.Layout) components.get(0);
            
           
            for( Metadata.LayoutSection ls : contLayout.layoutSections ) {
                
                LayoutSection section = new LayoutSection( ls.label, ls.layoutColumns.size() );
                      
                List<LayoutColumn> lstColumns = new List<LayoutColumn>();
                Integer maxFieldsInColumn = 0;
                for( Metadata.LayoutColumn lc : ls.layoutColumns ) {
                    
                    LayoutColumn column = new LayoutColumn();
                  
                    if( lc.layoutItems != null ) { 
                        
                        if( maxFieldsInColumn < lc.layoutItems.size() ) {
                            maxFieldsInColumn = lc.layoutItems.size();
                        }
                        for( Metadata.LayoutItem li : lc.layoutItems ) {
                            
                                
                            column.lstFields.add( new LayoutField( li ) );
                        }
                    }
                    
                    if( column.lstFields.size() > 0 ) {
                    	lstColumns.add( column );
                    }
                }
                
                
                if( maxFieldsInColumn > 0 ) {
                    for( Integer i = 0; i < maxFieldsInColumn; i++ ) {
                        for( Integer j = 0; j < lstColumns.size(); j++ ){
                            if( lstColumns[j].lstFields.size() > i ) {
                            	section.lstFields.add( lstColumns[j].lstFields[i] );    
                            }    
                            else {
                                section.lstFields.add( new LayoutField() );
                            }
                        }    
                    }    
                }
                
                lstSections.add( section );
            }
        }
        catch( Exception e ){
            System.assert(false, e.getLineNumber() + ' : ' + e.getMessage() );
        }
        return lstSections;
    }
    
    public class LayoutSection {   
	@AuraEnabled public String label;
    	@AuraEnabled public List<LayoutField> lstFields;
        @AuraEnabled public Integer totalColumns;
        public LayoutSection( String label, Integer totalColumns ) {
	    this.label = label;
            this.totalColumns = totalColumns;
            this.lstFields = new List<LayoutField>();
        }
    }
    
    private class LayoutColumn {
    	private List<LayoutField> lstFields;    
        public LayoutColumn() {
            this.lstFields = new List<LayoutField>();
        }
    }
    
    public class LayoutField {
        @AuraEnabled public String fieldName;
        @AuraEnabled public Boolean isRequired;
        @AuraEnabled public Boolean isReadOnly;
        
        public LayoutField() {}
        
        public LayoutField( Metadata.LayoutItem li ) {
        	
            this.fieldName = li.field;
            if( li.behavior == Metadata.UiBehavior.Required ) {
                this.isRequired = true;
            }
            else if( li.behavior == Metadata.UiBehavior.ReadOnly ) {
                this.isReadOnly = true;
            }    
        }
    }
}