OpenFn / lwala

1 stars 3 forks source link

Bulkify Salesforce job to upsert Households & Household Visits #88

Closed aleksa-krolls closed 1 year ago

aleksa-krolls commented 1 year ago

Background

Lwala's current CommCare-to-Salesforce workflows run on a real-time basis, with jobs that have message-filter triggers. To reduce its total number of OpenFn runs and improve system performance, it now wants to change its existing workflows to run on a cron, scheduled basis and to process records in bulk (rather than individual case updates).

Request

There is an existing job upsert_household_and_household_visit.js that is configured to process only 1 case record. It has 3 key operations:

  1. Query Salesforce Location__c table to search for existing location Ids to use in the Household mapping (for step 2)
  2. Upsert Houshold__c
  3. Upsert related Household Visit__c

Please bulkify this job and the above three operations to (1) handle an input of an array of cases, and (2) to leverage the Salesforce bulk API.

Workflow diagram

See the workflow steps in the red box for the operations https://lucid.app/lucidchart/e3411bda-1f0e-492f-b35d-6baf2dd3972a/edit?view_items=GVoMN_hukj_R&invitationId=inv_218cd740-0c18-446b-b225-b327e581f1b8

FYI - This is a really old job originally written by the client, so no mapping spec is available.

expression

⚠️ Please start work on the bulk-testing branch, and feel free to commit changes to this branch. ⚠️

Existing job to bulkify: https://github.com/OpenFn/lwala/blob/bulk-testing/commcare-salesforce-jobs/upsert_household_and_household_visit.js

The field-level mappings should be the same as the existing job.

state

output

There are 4 items in the array of sample state.data. This should result in:

toggl

Use the Lwala Bulk Workflows [2023] - 40 hrs toggl project.

aleksa-krolls commented 1 year ago

Hey @mtuchi this is ready to start work on today. @jayesse will support with testing. Please let us know if you have any questions you want to discuss over a call.

aleksa-krolls commented 1 year ago

@mtuchi here is the Salesforce docs on their SOQL query language: https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql.htm

aleksa-krolls commented 1 year ago

Tested locally, fixed any comments left regarding mapping issues, and it's now working well. Next steps will be even greater bulk testing.