💃 Simplify your inbound integrations 🕺

Peek at a "recent" REST enhancement

Good morning, Salesforce Nerds! Integrations can be hard. 💯 

Between sync vs async, data transformations, field mappings … it’s a mine field out there! 💥 

We’ve written about some of these complexities before -

But, we haven’t yet covered much in terms of the inbound integration capabilities of Salesforce.

There’s a lot. 😵‍💫 

As we always do, we’ll just start small. 🤏 

Today let’s peek at a “recent” enhancement made to the REST API that can help simplify things a bit …

i think it’s kinda cool

TABLE OF CONTENTS

INTRO TO REST QUERIES

A little background

One of the most important and well-known features of the Salesforce platform is their REST API.

This thing is loaded with goodies! 🍬🍭

Devs use the REST API to create, operator on, or search for data by sending HTTP requests to endpoints in Salesforce.

Powerful stuff.

A recent enhancement to the Query resource makes it even that much more powerful. 💪 

In a nutshell, the Query resource let’s you send SOQL queries to a standard endpoint in Salesforce.

Salesforce will execute the query and return up to 2000 records in it’s response. If more than 2000 records match the query criteria then a locator is also returned so you can retrieve the remaining records. 🧠 

This is ideal for devs building something outside of Salesforce that needs data from the org. 🔥 

Just OAuth, construct your query, hit the endpoint, then process the data.

Pretty slick, huh? I’ve always liked this endpoint whenever I had to write an integration like that.

But, there was always this built in limitation … 🫠 

NESTED QUERIES

Where’s the problem?

If your app needed to fetch related data more than two levels deep then you had some hoops to jump through. 🦘 

What I mean is this:

We’ve all seen queries like this

👆️ This query will return a list of Contacts for every Account returned.

What happens if my app requires that I go deeper? Say … three more levels deep?

Let’s say we now need:

AccountContactAssetWorkOrderWorkOrderLineItem

Well, it can be done, but it ain’t pretty.

The REST API v57.0 and earlier used to be have a two-level limit on parent-to-child relationships in a query.

Meaning, since our app requires us to go five levels deep now, we would be forced to make a series of API calls and run multiple SOQL statements to achieve our objective. 👎️ 

Run query to get Account and Contact records

Extract all Contact Ids

Run query to get Asset and WorkOrder records

Extract all WorkOrder Ids

Run query to get WorkOrderLineItem records

See what I mean by jumping through hoops now?

We needed to make three separate API calls and manage the relationships ourselves. 🤢 

QUERY MORE DATA

Expanding the depth

With v58.0 and above you can now send queries that go up to five 🖐️ levels deep natively!

That negates the need to spin up some solution like what we just talked about 👆️ and let’s us just send a single query to get all the that we need!

Like this:

mmmm, five levels deep

All we do now is package the query we need into an API callout and send it once. 💥 

We get a nice, nested JSON response back with all the data we need, relationships fully in-tact, and minimal resources consumed.

No more hoops! 🚫 

Unless you need more than five levels …

WRAPPING IT UP

Conclusion

At the end of the day, this is a value-add.  

Allowing devs to nest more SOQL queries will:

Reduce complexity

Save time

Lead to more efficient solutions

Save on API call limits

Anytime Salesforce can make experiences with their platform better it’s a win in my book! 🥳 

SOUL FOOD

Today’s Principle

"If you’re a technical lead, you need to be coding.”

Martin Fowler

and now....Salesforce Memes

to quote my daughter … yaaaaaas queen

🃏

i’ll still take the credit!

What did you think about today's newsletter?

Login or Subscribe to participate in polls.