๐Ÿ’ƒ An immensely needed base LWC ๐Ÿ•บ

OMG it's happening! ๐Ÿ˜

Good morning, Salesforce Nerds! Today the ChaCha has some extra pep in our step! โšก๏ธ๐Ÿ’ƒ๐Ÿ•บโšก๏ธ 

Some news that Iโ€™ve personally been waiting for years โŒ›๏ธ to arrive just hit the Developer Blog the other day! ๐Ÿฅณ 

And my inner programming geek couldnโ€™t be more stoked! ๐Ÿค˜๐Ÿ˜ 

Despite a handful of my legacy solutions now needing a refactor โ€ฆ ๐Ÿ˜ฒ 

Today letโ€™s spotlight ๐Ÿ”ฆ the addition of the Record Picker Component to the base LWC library!

Finally! ๐Ÿ™ 

oooof, gotta align this kind of dev work with their roadmap!

Agenda for today includes

  • An immensely needed base LWC

  • Daily Principle

  • All the Memes

An immensely needed base LWC

Today we will discuss -

๐Ÿ’ƒ What is it? ๐Ÿ•บ

๐Ÿ’ƒ Why should you care?๐Ÿ•บ

๐Ÿ’ƒ Letโ€™s see the code!๐Ÿ•บ

salesforce

Job Board | ๐Ÿ’ƒ Click Here ๐Ÿ•บ

Socials | ๐Ÿ’ƒ Linkedin | Instagram | Twitter!๐Ÿ•บ

๐Ÿค” What is it?

First things first -

We gotta give it up ๐Ÿ‘ for the Salesforce team building out the base Lightning Web Components!

The more this team churns out ๐Ÿ”„, the more streamlined and powerful our front-end solutions can be! ๐Ÿค– 

So kudos and a huge THANK YOU for your hard work. ๐Ÿ’ฏ 

Okay, so what is the Record Picker Component and why is my nerdy dev heart ๐Ÿ’“ going pitter patter over it?

Basically itโ€™s this: ๐Ÿ‘‡๏ธ 

Think about the control that gets added to the Page when you drag a Lookup field ๐Ÿ‘€ onto the Layout.

It looks like this:

When the user clicks ๐Ÿ–ฑ๏ธ the control it displays a list of records from configured SObject type and allows for various ways of searching. ๐Ÿ”๏ธ 

Weโ€™re all familiar with this. ๐Ÿ‘๏ธ 

But, did you know ๐Ÿค” that despite there being scores of base LWCโ€™s available to Salesforce devs - this was not one of them! โ‰๏ธ 

Effectively, that means if your solution required a custom LWC that contained a Lookup field like the one above โ˜๏ธ then your dev team needs to build one from scratch or come up with an alternative. ๐Ÿ”€ 

Through the years many of these โ€œcustom, reusable Lookups in LWCโ€ surfaced and hit github. ๐ŸŒ๏ธ 

They did the trick, but usually required a decent amount of development, testing, tweaking, etc.. ๐Ÿ™„ 

๐Ÿคท Why should you care?

With the addition โž• of a new base component your dev team wonโ€™t need to spend any time -

  • Hashing out requirements related to building one of these

  • Actually developing one

  • Tweaking an existing one

  • Cursing LOUDLY when they need to update one - AGAIN

Take it from me.

While it was kinda cool to make one of these, that only lasted a little while. ๐Ÿค 

These got squirrely ๐Ÿฟ๏ธ real quick!

We all know the only constant is change. ๐Ÿซ  

And that dude Russ from your payroll team is definitely going to break your implementation and then come to you with 7 change requests that donโ€™t make any sense whatsoever. ๐Ÿ˜† 

โ€ฆ Russ. Why is it always Russ?! ๐Ÿ˜  

I digress.

Bottom line - you should care for two main reasons:

  1. ๐Ÿ•›๏ธ Time - You and your devs are freed up to focus on important features for the business. Not boilerplate code to populate a simple Lookup field. โŒ 

  2. ๐Ÿ’ช Reliability - Salesforce provides base LWCโ€™s so we can use them as the building blocks of our custom apps. ๐Ÿ“ฆ๏ธ They give users a consistent look & feel, are matured/well-tested, simplify development effort, and are built using core Web Component standards. ๐Ÿคค 

๐Ÿ’ป๏ธ Letโ€™s see the code! 

Like Linus Torvalds said -

Itโ€™s hard to outline the code necessary to create one of these from scratch. ๐Ÿคทโ€โ™‚๏ธ 

But, we can check out a popular repo and get an idea ๐Ÿ’ก of what the LOE is to implement one.

Specifically - dig through the README file a bit and youโ€™ll see what I mean โ€ฆ

This just gets you the core of what you need:

  1. A way to run a SOQL query

  2. Select a record

  3. Pull the Id off the record

Now, tweak ๐Ÿ”ƒ this so you can get all of Russโ€™s stupid requests into it โ€ฆ ๐Ÿ™„ 

All of the sudden,๐Ÿ’ฅ BOOM๐Ÿ’ฅ, you now support a piece of ๐Ÿ’ฉ implementation.

Congratulations! ๐ŸŽ‰

Better days ๐ŸŒž๐Ÿ•ถ๏ธ๐ŸŒด are ahead, my friends.

Think of the Record Picker as your go-to Lightning Web Component that can quickly find and select Salesforce records.

All that will be required of your devs?

โŒ No Apex

โŒ No custom LWCโ€™s

The following bit of code will get you up and running! ๐Ÿ”ฅ 

recordPickerWithFilter.html

<template>
    <lightning-record-picker
        label="Select a record"
        placeholder="Search..."
        object-api-name="Contact"
        onchange={handleChange}
        matching-info={matchingInfo}
        display-info={displayInfo}
        filter={filter}
    ></lightning-record-picker>
</template>

recordPickerWithFilter.js

import { LightningElement } from "lwc";

export default class RecordPickerWithFilter extends LightningElement {
  matchingInfo = {
    primaryField: { fieldPath: "Name" },
    additionalFields: [{ fieldPath: "Title" }],
  };
  displayInfo = {
    additionalFields: ["Title"],
  };
  // filter Contacts having Accounts starting with "Madison"
  filter = {
    criteria: [
      {
        fieldPath: "Account.Name",
        operator: "like",
        value: "Madison%",
      },
    ],
  };

  handleChange(event) {
    console.log(`Selected record: ${event.detail.recordId}`);
  }
}

Trust me, from a developer perspective this is a big win! ๐Ÿ˜‰ 

Check out the blog post and tech specs!

Then let your friendly Salesforce devs know this is happening! ๐Ÿ’ƒ๐Ÿ•บ 

Daily Principle

โ€œThe most disastrous thing that you can ever learn is your first programming language.โ€

Alan Kay

and now....Your Daily Memes

lethal force warranted

aw, it ainโ€™t that bad. lots of regression testing tho

coming to a daily stand up near you

What did you think about today's newsletter?

Login or Subscribe to participate in polls.