SFDO-Tooling / Snowfakery

A tool for generating fake data that has relations between tables.
BSD 3-Clause "New" or "Revised" License
143 stars 32 forks source link

Add conditional handling after queries of SF Data #439

Open acrosman opened 3 years ago

acrosman commented 3 years ago

It would be helpful to be able to add data conditionally into a recipe depending on the results of the the SalesforceQuery.find_record plugin. Basically being able to add the data if the record is missing, while also being able to safely re-run a recipe against an org to expand a test data set after an initial pass.

Building off the example of the existing feature in the new docs. this would be something like:

- plugin: snowfakery.standard_plugins.Salesforce.SalesforceQuery
- object: Contact
  fields:
    FirstName: Bobby
    LastName: McFerrin
  friends:
    - object: CampaignMember
      fields:
        ContactId:
          reference: Contact
        CampaignId:
          if:
            - choice: 
                when: SalesforceQuery.find_record:
                    from: Campaign
                    where: name='Happiness Campaign'
                pick: SalesforceQuery.found_record
            - choice:
                pick: 
                - object: Campaign
                    fields:
                        name: Happiness Campaign
MannyAdumbire commented 2 years ago

Hey there @acrosman ! I think this feature would be extremely helpful.

Is there a current solution or workaround?

I opened another issue that maybe duplicate of this, but wasn't sure if what I found is lack of feature, or if it is an actual error.

658

acrosman commented 2 years ago

There isn't a solution within Snowfakery that I'm aware of at the moment. You could probably write a plugin that does it, but you'd likely have to re-implement much of the existing Salesforce Query plugin along the way -- which I don't recommend.

Another approach might be a CCI flow that checks for the record(s), runs a task to create as needed, and then runs the main recipe.

If you have just one or two records to check for it might make sense to just excerpt the needed records into their own recipe and add conditionally. That's essentially what we do for the NPSP Opportunity Naming setup in the sample recipe collection.

MannyAdumbire commented 2 years ago

@acrosman thanks for the ideas! I'll give the the cci flow route a try.