Fanny Zhingre
Fanny Zhingre

Reputation: 183

Insert or update to a salesforce by python

I want to insert or update to a salesforce record. by python but I get the following error.

The item of "SeqNo__c" is "202102-123" from that I specify the id of the record I want to change. it seems that it cannot find it at SeqNo__c.

If anyone knows, please let me know.

This code

from simple_salesforce import Salesforce
from datetime import datetime
import os
import json
import gzip
from pytz import timezone
import requests

#strDate = datetime.now().strftime("%Y%m%d")
#strTime = datetime.now().strftime("%H%M%S")

SALESFORCE_USERNAME = '[email protected]'
PASSWORD = '12345'
SECURITY_TOKEN = '12345'


# Authentication settings
sf = Salesforce(username=SALESFORCE_USERNAME,
password=PASSWORD,
security_token=SECURITY_TOKEN)
 
#Try bulk but also error

#data = [{'SeqNo__c': '202102-123', 'NewNO__c': '1'}]
#sf.bulk.Contact.update(data)

sf.Contact.upsert('SeqNo__c/202102-123',{'NewNO__c': '1'})

error code

Traceback (most recent call last):
  File "c:\Users\test\Documents\salesforce\sf_check.py", line 27, in <module>
    sf.Contact.upsert('SeqNo__c/202102-123',{'NewNO__c': '1'})
  File "C:\Users\test\AppData\Local\Programs\Python\Python39\lib\site-packages\simple_salesforce\api.py", line 694, in upsert
    result = self._call_salesforce(
  File "C:\Users\test\AppData\Local\Programs\Python\Python39\lib\site-packages\simple_salesforce\api.py", line 800, in _call_salesforce
    exception_handler(result, self.name)
  File "C:\Users\test\AppData\Local\Programs\Python\Python39\lib\site-packages\simple_salesforce\util.py", line 68, in exception_handler
    raise exc_cls(result.url, result.status_code, name, response_content)
simple_salesforce.exceptions.SalesforceResourceNotFound: Resource Contact Not Found. Response content: [{'errorCode': 'NOT_FOUND', 'message': 'Provided external ID field does not exist or is not accessible: SeqNo__c'}]
PS C:\Users\test\Documents\salesforce> 

Upvotes: 0

Views: 2189

Answers (1)

eyescream
eyescream

Reputation: 19612

Is the Contact.SeqNo__c field marked as external id? There's a checkbox in field definition that must be ticked. And your user needs to have a profile permission to at least see the field

Upvotes: 1

Related Questions