使用 Python 更新 Salesforce 中的 NULL 值时出现问题

问题描述 投票:0回答:3

我正在尝试使用 python 补丁请求将用户数据更新插入到 salesforce。我有一个数据框形式的数据集,其中包含多个空值。在尝试将数据更新插入到 salesforce 时,它会抛出一个错误,

{'message': 'Deserializing the instance of date from VALUE_STRING, value nan, cannot be executed or the request is missing a required field at [line:1, column:27]', 'errorCode': 'JSON_PARSER_ERROR'}

为了解决该错误,我尝试使用 None 和 Null 替换这些值,如下面的代码中所述。尽管如此,我还是收到了同样的错误。

df_1.fillna(value=None,method = None,inplace=True)
df_1 = df_1.replace(np.NaN,"null")

那么错误是:

{'message': 'Deserializing the instance of date from VALUE_STRING, value null, cannot be executed or the request is missing a required field at [line:1, column:27]', 'errorCode': 'JSON_PARSER_ERROR'}

任何可能的线索都会非常有帮助

python json pandas null salesforce
3个回答
0
投票

您需要找到一种方法来检查在发送之前生成的最终 JSON。

您可以使用 workbench 进行实验(登录后有“实用程序 -> REST Explorer”),并且通过普通 REST API,更新 是一个简单的操作

PATCH {your instance url}/services/data/v55.0/sobjects/Account/0017000000Lg8Wh

(输入您的帐户 ID)和正文(两种形式均可)

{
    "BillingCity" : null,
    "BillingCountry": ""
}

应清除字段。 A

"null"
不起作用,它算作一个字符串。

====

如果您使用“Bulk API 2.0”(https://trailhead.salesforce.com/content/learn/modules/api_basics/api_basics_bulk,我想您会注意到它是不同的,初始化作业的异步舞蹈,上传数据,开始处理,定期检查“是否完成了”...)对于 JSON 格式 null 也应该有效,对于 XML,您需要特殊标记,如果您的格式是 CSV - 它应该是

#N/A


0
投票

尝试

df.replace({np.nan: None}, inplace=True)

这相当于向 Salesforce 提交 Null 或空字符串值


0
投票

用空字符串 '' 替换 NA 应该适用于非数字数据类型,但会引发数字字段的 json 解析器错误。 切换到

import numpy as np
df.replace({np.nan: None}) 

使用 Python 对于 Salesforce 中的所有数据类型,似乎没有一个可以接受,至少在使用 SalesForce API 创建记录时是这样。

© www.soinside.com 2019 - 2024. All rights reserved.