Skip to content

Instantly share code, notes, and snippets.

@aleksa-krolls
Last active May 16, 2023 13:57
Show Gist options
  • Save aleksa-krolls/f31fb7da8df193812ae93f7914c79131 to your computer and use it in GitHub Desktop.
Save aleksa-krolls/f31fb7da8df193812ae93f7914c79131 to your computer and use it in GitHub Desktop.

Challenge

Your organization is collecting patient data in a custom EMR application.

To enable program monitoring and enhanced reporting, your M&E team wants you to start sending newly registered patient records from your EMR to its global M&E system built on Salesforce on a weekly basis.

You’ve been asked to design a workflow to:

  • extract data from your app (which has a REST API that returns data in JSON)
  • map the data elements to the Salesforce data model, and
  • sync patient records as vera__Beneficiary__c records in Salesforce

Training - Page 2

Request

Job 1: Get users from this endpoint https://jsonplaceholder.typicode.com/users

Job 2: For each user, upsert 1 vera__Beneficiary__c in Salesforce. See detailed mapping specifications: https://docs.google.com/spreadsheets/d/19ZJaudhQXy3J0lKcm5XdK3_ULNjDVMXaG7tuwlyc1zo/edit#gid=1822444315

Note that all of the Beneficiary records should be child to the parent Account record with External_ID__c: 'rtu_hospital'

Screen Shot 2023-05-15 at 9 51 31 AM

State

Job 1:

Job 2:

  • configuration: see slides for credential secrets
  • data: Use the final state from Job 1
  • adaptor: salesforce

Output

Each 1 user should result in 1 record upserted in Salesforce (1:1 mapping).

See Salesforce Adaptor docs for more on available functions and example jobs.

upsert('Obj_name', 'Ext_ID', {
  field1: "valueA",
  field2: "valueB"
});
@mtuchi
Copy link

mtuchi commented May 16, 2023

For Job 2 here are the options below

// option A
fn(state => {
  const records = state.data.map(i => {
    return {
      vera__External_ID__c: blah,
      Name: blah,
      vera__Username__c: blah,
      vera__Address__c: blah,
      vera__Province__c: blah,
      'vera__Hospital__r.vera__External_ID__c': blah,
      vera__Emergency_Contact_Phone__c: blah,
    };
  });
  return { ...state, records };
});

bulk(
  'sobject',
  { extIdField: 'extid', failOnError: true, allowNoOp: true },
  state => state.records
);

and...

// option b
each(
  dataPath('[*]'),
  upsert(
    'sobject',
    'ext_id',
    fields(
      field('Name', dataValue('name')),
      relationship('relationship_name__r', 'externalID-on-target', dataValue('path')).
      field('other_field__c', dataValue('thing.other')),
      field('age__c', dataValue('age'))
    )
  )
);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment