πŸ’ƒ 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.