Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

salesforce update function docs #821

Open
wants to merge 20 commits into
base: epic/salesforce
Choose a base branch
from
Open

salesforce update function docs #821

wants to merge 20 commits into from

Conversation

mtuchi
Copy link
Collaborator

@mtuchi mtuchi commented Nov 12, 2024

Summary

  • Update params documentation and improve examples in salesforce adaptor
  • Add query option in request function

Fixes #664

AI Usage

Please disclose how you've used AI in this work (it's cool, we just want to know!):

  • Code generation (copilot but not intellisense)
  • Learning or fact checking
  • Strategy / design
  • Optimisation / refactoring
  • Translation / spellchecking / doc gen
  • Other
  • I have not used AI

You can read more details in our Responsible AI Policy

Review Checklist

Before merging, the reviewer should check the following items:

  • Does the PR do what it claims to do?
  • If this is a new adaptor, added the adaptor on marketing website ?
  • Are there any unit tests?
  • Is there a changeset associated with this PR? Should there be? Note that
    dev only changes don't need a changeset.
  • Have you ticked a box under AI Usage?

@josephjclark
Copy link
Collaborator

@mtuchi I assume this replaces #799?

@mtuchi mtuchi changed the title Sf jsdocs salesforce update function docs Nov 12, 2024
@mtuchi
Copy link
Collaborator Author

mtuchi commented Nov 12, 2024

@josephjclark yes it will replace #799, I will close the PR once i am done with the changes

@mtuchi mtuchi requested a review from josephjclark November 12, 2024 18:38
@mtuchi mtuchi marked this pull request as ready for review November 12, 2024 18:38
This was referenced Nov 12, 2024
Copy link
Collaborator

@josephjclark josephjclark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @mtuchi, sorry for the delay!

I've done a detailed review of the docs and this PR and suggested a bunch of improvements (sorry it's a long list!). There's a bunch of older problems that we should take the opportunity to fix, and some open questions too.

* Options provided to the Salesforce bulk API request
* @typedef {Object} BulkOptions
* @public
* @property {string} extIdField - External id field.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait is this required? If it's required it probably shouldn't be on the options object.

Also (and I know this is a problem across the docs) we shouldn't mark options on an optional object as optional... because they're implicitly optional! And anyway who knows what the ugly brackets around the option name mean?"

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's required only for upsert operation, I have update the docs to reflect that

* @param {integer} [options.pollInterval=6000] - Polling interval in milliseconds.
* @param {integer} [options.pollTimeout=240000] - Polling timeout in milliseconds.
* @param {BulkOptions} options - Options passed to the bulk api.
* @state {SalesforceState}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is written to state.data if you call bulk? Should we document it properly?

The generic Operation results really isn't very helpful

image

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made some improvements

Screenshot 2024-12-10 at 11 29 26 AM

* @param {boolean} [options.failOnError=false] - Fail the operation on error.
* @param {integer} [options.pollInterval=6000] - Polling interval in milliseconds.
* @param {integer} [options.pollTimeout=240000] - Polling timeout in milliseconds.
* @param {BulkOptions} options - Options passed to the bulk api.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah this is a bit confusing. Some of these are OpenFn options, others are passed through to the jsforce API

This is a problem with the wording of options passed to the bulk API (because most options are NOT passed to the bulk API), and on the BulkOptions type.

Maybe we should use generic language like "Options to configure the request", then we should document our own options (as we do now), and THEN we should link to the jsforce options (ensuring we're linking to the right library version). Perhaps we say like "Options to configure the request. In addition to these, you can pass any of the options supported by the jsforce API [link]"

Then the pattern we establish here needs rolling out to other APIs

Checkout the docs for commcare.bulk - where we mostly link to commcare docs directly

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated: as this is a major version bump anyway, how do you feel about moving the operation option to the options object, and defaulting it to "upsert"?

I don't know how common it is to set this - but it feels like it should be an option rather than a required field.

Upsert is probably the most common case but I guess it could be dangerous if users aren't aware they're doing it 🤔

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly i think bulk() needs to be improved. There are couple of operation that i have never seen being used. For example queryAll, query, hardDelete i don't know if they work at all.

But as for suggestion i think we should keep the function signature the same

packages/salesforce/src/Adaptor.js Show resolved Hide resolved
packages/salesforce/src/Adaptor.js Outdated Show resolved Hide resolved
* @param {object} options - Options passed to the bulk api.
* @param {boolean} [options.autoFetch=false] - Fetch next records if available.
* @param {function} callback - A callback to execute once the record is retrieved
* @param {(string|function)} qs - A SOQL query string or a function that returns a query string. Must be less than 4000 characters in WHERE clause
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea of passing a function is (or should be) so normal and openfn-y that I don't want to document it explicitly here.

This is basically a very old documentation pattern and we should eradicate it where we can.

Also, as before, please rename qs to query

packages/salesforce/src/Adaptor.js Outdated Show resolved Hide resolved
packages/salesforce/src/Adaptor.js Show resolved Hide resolved
packages/salesforce/src/Adaptor.js Outdated Show resolved Hide resolved
@@ -548,6 +608,7 @@ export function query(qs, options = {}, callback = s => s) {
* @magic externalId - $.children[?(@.name=="{{args.sObject}}")].children[?(@.meta.externalId)].name
* @param {(object|object[])} records - Field attributes for the new object.
* @magic records - $.children[?(@.name=="{{args.sObject}}")].children[?([email protected])]
* @state {SalesforceState}
* @returns {Operation}
*/
export function upsert(sObjectName, externalId, records) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The general documentation for this function isn't terribly good and is wierdly formatted. I think there's a missing full stop? But it's wierd that we say "externalID must be specified". It's not documented as optional or anything.

I'm also not a great fan of Array.<object>

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have updated the docs for upsert and add a link to https://jsforce.github.io/document/#upsert

Also for records param. I have updated the type to be {(Object|Object[])} which is the accurate representation of the type

@mtuchi
Copy link
Collaborator Author

mtuchi commented Dec 10, 2024

Hiya @josephjclark sorry for long overdue delay on this PR, I have finished working on your feedback, Please give this another round of review

@mtuchi mtuchi requested a review from josephjclark December 10, 2024 12:16
@josephjclark
Copy link
Collaborator

Thank you @mtuchi ! Sorry it's been an epic 😅 I'll review this tomorrow 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants