From a95debe4c51d1b05518b7839d054c49fa39e502e Mon Sep 17 00:00:00 2001 From: Renan Butkeraites Date: Mon, 9 Dec 2024 17:41:47 -0300 Subject: [PATCH] HGI-6745: get linked object ref --- target_salesforce_v3/sinks.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/target_salesforce_v3/sinks.py b/target_salesforce_v3/sinks.py index 3432cf0..c815f70 100644 --- a/target_salesforce_v3/sinks.py +++ b/target_salesforce_v3/sinks.py @@ -1078,6 +1078,18 @@ def link_attachment_to_object(self, file_id, linked_object_id): else: raise Exception(f"Failed while trying to link file {file_id} and object {linked_object_id} because ContentDocumentId was not found") + if isinstance(linked_object_id, dict): + # they're using an external id, we need to look it up + link = list(linked_object_id.keys())[0] + sobject, external_id = link.split("/") + params = {"q": f"SELECT Id FROM {sobject} WHERE {external_id} = '{linked_object_id[link]}'"} + link_obj = self.request_api("GET", endpoint=content_endpoint, params=params) + link_obj = link_obj.json() + if link_obj.get("records"): + linked_object_id = link_obj['records'][0]['Id'] + else: + raise Exception(f"Could not find matching {sobject} with {external_id} = '{linked_object_id[link]}'") + endpoint = "sobjects/ContentDocumentLink" record = { "ContentDocumentId": content_document_id,