我正在使用 Simple Salesforce Python 库将 10 个联系人从外部数据源导入 Salesforce。
背景:一个帐户可以在联系人中有多个记录。我在 Account 和 Contact 中都创建了 ExternalAccountID 字段。与正在导入的 10 个联系人相关的帐户已加载到 Account 对象中。Account 对象中的'ExternalAccountID' 包含'legacy account id'(例如1234_LegacyAccountId)。
Account 中的“ExternalAccountID”字段为“External”且唯一。Contact 中的“ExternalAccountID”不是唯一的,因为每个帐户可以有多个联系人。
Contact 中的“ExternalAccountContactID”是“External”和“Unique”。此字段由旧版帐户 ID + 旧版联系人 ID 组成。此字段用于更新联系人数据。
问题:来自 Account 对象的“Id”没有自动填充到“Contact”对象的 AccountId 字段中,10 个联系人的帐户已经在 Account 对象中可用。
当前的解决方案使用 Pandas Dataframe 来插入 10 个联系人。这是查询源数据并在 Salesforce 目标服务器中插入数据的代码片段。
information = sf.query_all(query= sql_code)
table = pandas.DataFrame(information['records']).drop(columns='attributes')
table['ExternalAccountID'] = table.Id
table['ExternalAccountContactID']=(table['AccountId'].astype(str)) +"_"+
(table['Id'].astype(str))
new_df = table[['Name','Email', 'ExternalAccountID', 'Department']]
new_df = new_df.rename(columns=
{"ExternalAccountID":"ExternalAccountID__c","Name":"Name","Email":"Email",
"Department":"Department"})
results_json = new_df.to_json(orient='records')
records_upsert = json.loads(results_json)
print ("Records to be upserted")
sft.bulk.Contact.upsert(records_upsert,'ExternalAccountContactID__c'
,batch_size=10000,use_serial=True)
我应该在脚本中的哪里指定需要引用相关的 Account 对象,以便可以检索 Account 中的“Id”?在 Data Loader 中,我可以插入数据,并且 Contact 中的“AccountId”正在自动填充,如何使用 Python 实现相同的结果?任何提示