From 5a652459583a703f893bfa9241d6982e7dc08b04 Mon Sep 17 00:00:00 2001 From: Vinicius Mesel <4984147+vmesel@users.noreply.github.com> Date: Tue, 19 Dec 2023 13:48:35 -0300 Subject: [PATCH] Adds permission ids --- target_salesforce_v3/client.py | 8 +++++++- target_salesforce_v3/sinks.py | 3 +++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/target_salesforce_v3/client.py b/target_salesforce_v3/client.py index 9ef8d73..f6bf53f 100644 --- a/target_salesforce_v3/client.py +++ b/target_salesforce_v3/client.py @@ -37,6 +37,12 @@ def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.api_version = self.config.get("api_version", "55.0").replace("v", "") + @property + def permission_set_ids(self): + params = {"q": "SELECT Id FROM PermissionSet"} + response = self.request_api("GET", endpoint="query", params=params, headers={"Content-Type": "application/json"}) + return [r["Id"] for r in response.json()["records"]] + @property def http_headers(self) -> dict: """Return the http headers needed.""" @@ -380,7 +386,7 @@ def add_custom_field(self,cf,label=None): # But then, we need to add the permissions to the Task sObject # So we change it back again from `Activity` -> `Task` sobject = 'Task' - for permission_set_id in getattr(self, "permission_set_ids", []): + for permission_set_id in self.permission_set_ids: self.update_field_permissions(permission_set_id, sobject_type=sobject, field_name=f"{sobject}.{cf}") def update_field_permissions(self,permission_set_id, sobject_type, field_name): diff --git a/target_salesforce_v3/sinks.py b/target_salesforce_v3/sinks.py index ac48279..b8595c5 100644 --- a/target_salesforce_v3/sinks.py +++ b/target_salesforce_v3/sinks.py @@ -43,6 +43,9 @@ def preprocess_record(self, record: dict, context: dict): if isinstance(record.get("campaigns"), str): record["campaigns"] = json.loads(record.get("campaigns")) + if record.get("company") and not record.get("company_name"): + record["company_name"] = record["company"] + record = self.validate_input(record) # Handles creation/update of Leads and Contacts