Skip to content

Commit

Permalink
Adds upsert behavior (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
vmesel authored Dec 7, 2023
1 parent 4a89408 commit 73338ca
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions target_salesforce_v3/sinks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from __future__ import annotations

import json

import urllib
from target_salesforce_v3.client import SalesforceV3Sink

from hotglue_models_crm.crm import Contact, Company, Deal, Campaign,Activity
Expand Down Expand Up @@ -741,8 +741,17 @@ def preprocess_record(self, record, context):
self.logger.info("Skipping record, because it was not found on Salesforce.")
return
record["object_type"] = object_type

# Try to find object instance
if record.get("Email"):
query = "".join(["FIND {", record['Email'], "} ", f" IN ALL FIELDS RETURNING {object_type}(id)"])
req = self.request_api("GET", "search/", params={"q": query})

if req.json().get("searchRecords"):
record["Id"] = req.json()["searchRecords"][0]["Id"]

return record

def upsert_record(self, record, context):
state_updates = dict()

Expand Down

0 comments on commit 73338ca

Please sign in to comment.