OpenFn / adaptors

The new home for OpenFn adaptors; re-usable connectors for the most common DPGs and DPI building blocks.
GNU General Public License v3.0
4 stars 8 forks source link

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

Open mtuchi opened 1 month ago

mtuchi commented 1 month ago

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

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