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

Error when SaleforceQuery can't find matching record. #658

Open
MannyAdumbire opened this issue May 8, 2022 · 3 comments
Open

Error when SaleforceQuery can't find matching record. #658

MannyAdumbire opened this issue May 8, 2022 · 3 comments

Comments

@MannyAdumbire
Copy link

MannyAdumbire commented May 8, 2022

I'm trying to seed Salesforce org using values from Spreadsheet, and seem close to having it work, but getting some errors.

The recipe should use SalesforceQuery to prematch any Contacts with the same email addresses as one in CSV Dataset.
If no match was found, a new Contact record should be created.

This recipe works when a Contact matching the email address already exists in the Salesforce org.
However, the same recipe throws an error if no match was found.

snowfakery-sf-upsert-null-error

How can I conditionally upsert pre-existing matched record in recipe, or create a new one if no matches were found?

Really appreciate any help!

CSV Dataset

Company,Email
RealCompany,nytggkdrfigge@snow.fake
RealCompany,jlqdnidzdbvgic@snow.fake
RealCompany,ppqkxfzxxyojwnwhke@snow.fake
RealCompany,mlkbarzbjvbykqjm@snow.fake
RealCompany,inmfgbpufljyhmrycp@snow.fake
RealCompany,phrojiaydrbmjosiu@snow.fake
RealCompany,fcgshlpfccnavyhgu@snow.fake
RealCompany,numrbbqyrmqrqrwql@snow.fake
RealCompany,blqyqpugry@snow.fake
RealCompany,rttcjftzhr@snow.fake

Recipe

- plugin: snowfakery.standard_plugins.Salesforce.SalesforceQuery
- plugin: snowfakery.standard_plugins.datasets.Dataset

- object: Account
  nickname: account_new
  for_each:
    var: contact_row
    value:
      Dataset.iterate:
        dataset: contact-list-company-email.csv
  fields:
    Name: ${{contact_row.Company | trim }}
    # Create hidden field to store found record.
    __contact_found:
      SalesforceQuery.random_record:
        from: Contact
        fields: Id,Email
        where: Contact.Email='${{contact_row.Email | trim}}'
    # Create hidden field for the new record to be used if no pre-existing matches Contact is found.
    __contact_new:
      - object: Contact
        fields:
          Email: ${{contact_row.Email | trim }}
          hed__AlternateEmail__c: ${{contact_row.Email | trim }}
          hed__Preferred_Email__c: Alternate Email
  friends:
   - object: Campaign
     nickname: Campaign1
     fields:
       Name: 
         fake: CatchPhrase
       IsActive: true
   - object: CampaignMember
     fields:
       Campaign: 
         reference: Campaign1
       ContactId:
         if:
           - choice:
               # If a Contact was found matching this email address, the use the found record.
               when: ${{ account_new.__contact_found.Id!=NULL }}
               pick: ${{ account_new.__contact_found.Id }}
           - choice:
               # Else default to making a new Contact 
               pick: 
                 reference: __contact_new
@MannyAdumbire
Copy link
Author

ps - I initially tried to find matches using "SalesforceQuery.find_record" and only switched to"SalesforceQuery.random_record" after that didn't work

@prescod
Copy link
Contributor

prescod commented May 11, 2022

There is a new, beta, feature for Snowfakery for doing upserts. I will try to get it into this week's CumulusCI release so you can try it.

@MannyAdumbire
Copy link
Author

MannyAdumbire commented May 13, 2022

The new feature sounds exciting!

I just tried( and failed with error) to use upsert feature in cci mapping step- https://cumulusci.readthedocs.io/en/latest/data.html?highlight=snowfakery#upsert

Honestly, I'm amazed it actually almost works just using Snowfakery! The well-written documentation has helped me out a ton too.

I'm always happy to beta test ;)

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

No branches or pull requests

2 participants