Simple-salesforce: perform a bulk insert on a lookup field

365 Views Asked by At

I am attempting to perform a bulk insert to a custom object in salesforce using the simple-salesforce library.

I have a lookup field with a the api endpoint 'Account_Name__c', along with a few others. Here's a sample of what I'm sending through:

[{'ID__c': '123456789',
  'Date__c': '2022-12-21',
  'Total_Transactions__c': 1,
  'Amount__c': -492.81,
  'Account_Name__c': 'a1j1234567'}]

I've tried to insert with the account name, it returns this error:

[{'success': False,
  'created': False,
  'id': None,
  'errors': [{'statusCode': 'FIELD_INTEGRITY_EXCEPTION',
    'message': 'Account Name: id value of incorrect type: a1j1234567',
    'fields': ['Account_Name__c']}]}]

If I pull that field out of there, the insert goes through fine but of course doesn't update the field that is a lookup linking it to the account object.

Is there a way to do this using simple-salesforce?

1

There are 1 best solutions below

0
On

Updating a lookup field is simple but the reference needs to be specific. You do not need to reference the relationship api, just the lookup field, then in the lookup field you need to place the account ID.

[{'ID__c': '123456789',
  'Date__c': '2022-12-21',
  'Total_Transactions__c': 1,
  'Amount__c': -492.81,
  'Account_Name__c': 'accountid1234567'}]

In the end what I was doing was inserting the wrong identifier into the field. To test if you are looking at the right identifier, you can see up in end of the url on the record you're looking at if you're using the correct id field. Once you have it it is as simple as referencing the appropriate account identifier.