Posts

Showing posts with the label IN

Salesforce Fact #962 | SOQL syntax error in Get Records while using IN operator and sorting

Image
We need to be careful while using the IN operator in Get Records element along with sorting of the result by a field. If the text collection is null which is used in the Id filter, the underlying SOQL throws a syntax error. As a best practice, it is always preferred to check if the collection var is null or not. This also avoids one SOQL query. Attached are the screenshots. Reference:  https://trailhead.salesforce.com/trailblazer-community/feed/0D54S00000JfvwISAR

Salesforce Fact #953 | Limit error in Get Records while using IN operator

Image
We need to be careful while using the IN operator in Get Records element in record-triggered flow. If the text collection is empty, it seems Salesforce runs a query to fetch all the records of that sobject and the number of query rows are counted in the governor limit. So, if the total number of records for that sobject is more than 50000, it throws limit error. Fix would be to always check if the collection is empty or not, before using it in the IN operation. In this example, varIds is an empty text collection used in IN operation to fetch the account records. However, the number of query rows returned is 136 instead of 0, which is the total number of account records in the org. Attached are the screenshots.

Salesforce Fact #651 | IN operator with Day_Only()

We can use IN operator to put filter on multiple dates while using Day_Only function. For example, the below SOQL returns the accounts which were created on 27th and 28th Jan of 2023. SELECT Id, Name, CreatedDate FROM Account WHERE Day_Only(CreatedDate) IN (2023-01-27, 2023-01-28) The same works perfectly with bind variables as well: Date d1 = Date.parse('01/27/2023'); Date d2 = Date.parse('01/28/2023'); List<Account> accList = [SELECT Id, Name, CreatedDate FROM Account WHERE Day_Only(CreatedDate) IN (:d1, :d2)];