简单Salesforce日期上传

2024-09-27 07:21:23 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用openpyxl和SimpleFoce将opportunity上传到Salesforce。下面是我目前试图让上传工作。我已经尝试过了,一个普通的excel日期对象,一个excel日期对象作为字符串,一个excel日期对象作为一个时间部分被截断的字符串

ws = wb["Opportunities"] # Gets the Opportunities sheet
recordTypeMap = getRecordTypes(sf, ws, 1, "Opportunity")
insertOpportunities = []
try:
    logInfo("Reading Opportunities")
    for row in ws.iter_rows(min_row=2, values_only=True):
        insertOpportunities.append(
            {'RecordTypeId': recordTypeMap.get(row[0]), 'OwnerId': users.get(row[1]), 'AccountId': accounts.get(row[2]),
            'Name': row[3], 'Type': row[4], 'Budget_Confirmed__c': row[5], 'Discovery_Completed__c': row[6],
            'ROI_Analysis_Completed__c': row[7], 'EEP_Loss_Reason__c': row[8], 'CloseDate': str(datetime.datetime.now(pytz.UTC)), 'StageName': row[10],
            'LeadSource': row[13], 'EEP_Producer_CBU__c': row[14],
            'EEP_Producer_Distribution_Channel__c': row[15], 'EEP_Restricted_Access__c': row[16]})
        logging.info(insertOpportunities)
except Exception as ex:
    logError("Could not read Opportunities", ex)

try:
    logInfo("Creating Opportunities")
    Opportunities = sf.bulk.Lead.insert(insertOpportunities, batch_size=100)
    logInfo("Created Opportunities")
    logging.info(Opportunities)
except Exception as ex:
    logError("Could not create Opportunities", ex)

日期对象出现一个无法JSON序列化的错误,其他所有对象都出现以下错误。下面的信息是试图发送给Salesforce的内容,错误是发送回的错误消息

INFO: [{'RecordTypeId': '0124W000001lDpAQAU', 'OwnerId': '0056t000000ENvxAAG', 'AccountId': '0016t000002tw3UAAQ', 'Name': 'Test op 1', 'Type': 'Existing Business', 'Budget_Confirmed__c': True, 'Discovery_Completed__c': True, 'ROI_Analysis_Completed__c': True, 'EEP_Loss_Reason__c': None, 'CloseDate': '2021-06-02 14:08:36.995182+00:00', 'StageName': 'Closed Won', 'LeadSource': 'Purchased List', 'EEP_Producer_CBU__c': None, 'EEP_Producer_Distribution_Channel__c': None, 'EEP_Restricted_Access__c': False}]    
ERROR: Malformed request Response content: {'exceptionCode': 'InvalidBatch', 'exceptionMessage': 'Records not processed'}

我已经获取了这些精确的数据,并手动创建了一个机会,因此我看到错误的唯一原因是日期的格式


Tags: producer对象truegetws错误notexcel
1条回答
网友
1楼 · 发布于 2024-09-27 07:21:23

正确的日期格式如“2021-06-02”所述。这里的错误只是引用了其中一个项目中的错误自定义字段。如果您遇到此类错误,请尝试删除不需要的字段,以查找导致错误的字段

相关问题 更多 >

    热门问题