Snowfakery icon indicating copy to clipboard operation
Snowfakery copied to clipboard

Add conditional handling after queries of SF Data

Open acrosman opened this issue 4 years ago • 3 comments

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

acrosman avatar Jul 13 '21 20:07 acrosman

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

MannyAdumbire avatar May 08 '22 19:05 MannyAdumbire

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.

acrosman avatar May 08 '22 20:05 acrosman

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

MannyAdumbire avatar May 09 '22 00:05 MannyAdumbire