OpenFn / OpenFn/adaptors

Add support for `throwOnEmpty` in query function for Salesforce integration to handle zero results

Open
#595 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
24
Forks
41
Avg merge
3d 13h
Merged PRs (30d)
12

Description

Description

We need to enhance our query function in the Salesforce integration by adding support for the throwOnEmpty feature. This feature should throw an exception or handle the case where the query returns zero results.

Current Behavior

Currently, when the query function in our Salesforce integration returns zero results, the job proceeds without any indication or exception. This leads to a tedious error handling job code
Eg:

 const queryResult = state.references[0][0];
    const accountExists = queryResult && queryResult.totalSize > 0;
    if (!accountExists) {
      console.log(`Account with External ID: ${state.account.External_ID__c} not found in Salesforce`);
    }
Expected Behavior

When the throwOnEmpty parameter is set to true, the query function should:

  1. Throw a specific exception when a query returns zero results.
  2. Provide a clear error message indicating that no results were found.
Steps to Reproduce
  1. Call the query function with parameters that will result in zero results.
  2. Observe that no exception is thrown and the process continues as usual.
Proposed Solution
  • Add a throwOnEmpty parameter to the query function signature.
  • Implement logic to check the result size is bigger than 0.
  • If throwOnEmpty is true and the result set is 0, throw a specific exception with a descriptive error message.

Please feel free to reach out for any further details or clarification on this feature request. Thank you!

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the Salesforce integration's query function and read how its result size is currently handled. Reproduce a query with zero results, then verify that enabling throwOnEmpty produces a specific, descriptive exception while existing behavior remains unchanged when it is not enabled.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
api, backend
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.