Skip to main content
Best answer

Does the Salesforce WHERE Clause support ORDER BY?


SOQL allows the use of ORDER BY in a SELECT statement.

Is there a way to set this up in zapier’s WHERE clause?

 

Best answer by SamBBest answer by SamB

Hey folks,

I’m happy to report that the feature requests @nicksimard mentioned here have since been closed! 🎉

It’s now possible to set the order by as well as the order direction in the Find Record by Query Search (Salesforce) action:
692d234bb0e4b04f5bd170f017b03582.png

And there’s a Find Record(s) by Query action that would allow you to return multiple records from a search:
4f4a36a5ca565d5d3a242a0ab33013dc.png

We hope you’re able to test this out in your Zaps soon! And if you run into any trouble please reach out in the Community or get in touch with Support to let us know. 

In the meantime, happy Zapping! ⚡

View original
Did this topic help you find an answer to your question?
This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

16 replies

Troy Tessalone
Forum|alt.badge.img+14
  • Zapier Expert
  • 31147 replies
  • February 12, 2021

  • Author
  • Beginner
  • 6 replies
  • February 12, 2021

I did before I posted this but not sure how that article helps.

As you can probably tell, you can’t write a full SOQL query in zapier.

It only allows specifying the WHERE clause whereas SORT BY is usually declared after SELECT.


Troy Tessalone
Forum|alt.badge.img+14
  • Zapier Expert
  • 31147 replies
  • February 12, 2021

@WorkHard
Perhaps try this Salesforce Search instead, followed by a Code step to sort.

 


  • Author
  • Beginner
  • 6 replies
  • February 12, 2021

Appreciate the alternative suggestion but you lost me here.

Zapier will ALWAYS return 1 result from a “Find Record” step.

Meaning, even if my object contains multiple rows, zapier will ALWAYS only return 1.

So not sure how the “Code step” can pull another record.


Troy Tessalone
Forum|alt.badge.img+14
  • Zapier Expert
  • 31147 replies
  • February 12, 2021

@WorkHard

There are 3 different Find Record searches for Salesforce.

One of which may return multiple records.

Give that a try.

 

I could be wrong tho…

How search actions work

Salesforce search actions return the most recently created record that meets the search criteria, even if there are multiple records that match.

 

And if that is not sufficient, then you may have to get more technical and leverage the Salesforce API via a Webhooks step or Code step: https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/intro_what_is_rest_api.htm

 

Webhooks: https://zapier.com/apps/webhook/integrations

Code: https://zapier.com/apps/code/help


  • Author
  • Beginner
  • 6 replies
  • February 12, 2021

Uhm, I don’t think that’s how it works.

Find Record(s) lets you search for multiple records, yes, but it doesn’t return multiple records from the same record.

Meaning, I can search for multiple IDs (enter each Id separated by a comma) but the result from each of those IDs will only be 1 record even if there are multiple items/results for each Id.

Id Date
1 01/01/2021
1 01/05/2021
2 02/01/2021
2 02/05/2021

 

In the example above Find Record(s) will let me pick Record.Id: 1,2

But the result will still be 1: 01/01/2021 and 2: 02/01/2021.

It won’t see the other row from the same ID.


Troy Tessalone
Forum|alt.badge.img+14
  • Zapier Expert
  • 31147 replies
  • February 12, 2021

@WorkHard 

You can try to see if including an ORDER BY clause works with the WHERE clause, but as you suspect it may not work.

 

Thus you may have to get more technical and leverage the Salesforce API via a Webhooks step or Code step: https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/intro_what_is_rest_api.htm

 

Webhooks: https://zapier.com/apps/webhook/integrations

Code: https://zapier.com/apps/code/help


  • Author
  • Beginner
  • 6 replies
  • February 12, 2021

I’m already using webhooks but that wouldn’t work for this because I need the result on the fly.

Do you know if I can call the salesforce API in the Code step (javascript)? Can’t find any examples so this is most likely beyond my zapier knowledge.

 


Troy Tessalone
Forum|alt.badge.img+14
  • Zapier Expert
  • 31147 replies
  • February 12, 2021

@WorkHard

Webhooks app in a Zap has these actions available to interact with an app’s API

 

 

Code app examples using JavaScript for HTTP requests

https://zapier.com/help/create/code-webhooks/javascript-code-examples-in-zaps#step-2


  • Author
  • Beginner
  • 6 replies
  • February 12, 2021

I think I tried going this path a while ago and got stuck at the fact that all these examples are simple http without authentication. 

There’s no way I can figure out how to authenticate with salesforce from here because you can’t use the existing connection here.


Troy Tessalone
Forum|alt.badge.img+14
  • Zapier Expert
  • 31147 replies
  • February 12, 2021

@WorkHard 

Correct, using Code or Webhooks you’ll have to manage the connection credentials separately than the authenticated app in Zapier as defined by the app’s API authentication protocols.

Webhooks app as actions has some basic authentication fields available.

 


Troy Tessalone
Forum|alt.badge.img+14
  • Zapier Expert
  • 31147 replies
  • February 12, 2021

@WorkHard 

If you’re still stuck, perhaps consider hiring a Zapier Expert: https://zapier.com/experts


  • Author
  • Beginner
  • 6 replies
  • March 4, 2021

Thanks, Troy.

Basic authentication is not exactly enterprise security level. This won’t fly in our org.

The real solution here is for zapier to implement the ORDER BY clause rather than us hiring someone to recreate the wheel.

 

This would help users that are limited by Zapier’s API because not only it can only return 1 record out of multiple, the decision of which record to return is very much up in the air and not guaranteed.

The ORDER BY clause with its DESC, ASC, and LIMIT modifiers would greatly help everyone to return which result they want and even return multiple by creating multiple steps in the zap.

 

 


@WorkHard I agree! I feel like the need to order the result table is pretty basic. What would be amazing is if we could just use 100% SOQL to query a record or records. 


nicksimard
Forum|alt.badge.img+11
  • Zapier Staff
  • 2115 replies
  • June 28, 2021

Hi @WorkHard and @Jay Lopez!
We have a couple of open feature requests (one to support ORDERBY and the other to return multiple records from a search). I’ve added you both to those requests, so you’ll be notified via email should those they be implemented.


SamB
Community Manager
Forum|alt.badge.img+11
  • Community Manager
  • 7597 replies
  • Answer
  • June 21, 2024

Hey folks,

I’m happy to report that the feature requests @nicksimard mentioned here have since been closed! 🎉

It’s now possible to set the order by as well as the order direction in the Find Record by Query Search (Salesforce) action:
692d234bb0e4b04f5bd170f017b03582.png

And there’s a Find Record(s) by Query action that would allow you to return multiple records from a search:
4f4a36a5ca565d5d3a242a0ab33013dc.png

We hope you’re able to test this out in your Zaps soon! And if you run into any trouble please reach out in the Community or get in touch with Support to let us know. 

In the meantime, happy Zapping! ⚡