0

I'm trying to use Python's simple_salesforce library to upsert on an object called Member Plan that has a required field called MemberId which is a Master-Detail relationship with the Account object.

I have always been able to create / upsert records in Salesforce with this library / API no problem, but not sure how to do it with fields that are Lookup or Master-Detail types.

when I try to use simple_salesforce to create or upsert a new MemberPlan object using an arbitrary MemberId, sf.MemberPlan.create(parameters)

I get this error:

[{'message': 'invalid cross reference id', 'errorCode': 'INVALID_CROSS_REFERENCE_KEY', 'fields': []}]

If I try to do a SOQL Query on the existing MemberIds in the Account object with this query: accounts = sf.query("SELECT Person_ID__c FROM Account") And I use one of those to upsert or create MemberPlan objects I get this:

[{'message': 'duplicate value found: <unknown> duplicates value on record with id: <unknown>', 'errorCode': 'DUPLICATE_VALUE', 'fields': []}]

What's the proper way to do this?

-- EDIT: Here is the parameters I tried to pass:

session_id, instance = SalesforceLogin(username=dev_user, 
password=dev_pw, 
security_token=dev_token, 
domain='test')
plan = SFType('MemberPlan', session_id, instance, sf_version='47.0')
plan.create(
{'Name' : 'TestAPI', 'MemberId' : '001m000000xnFydAAE'})
  • Are you populating the field MemberId with a 15 or 18 character Salesforce Id, or with the content of a custom field Person_Id__c? This makes a significant difference. Are the schema entities Member Plan and MemberId provided by a package such as Health Cloud? – David Reed May 11 at 3:11
  • The content of a custom field Person_Id__c which is an 18 character external Id. The schema entities are indeed from Health Cloud. – Danny Vu May 11 at 3:18
  • We would need to see the parameters you're passing in to debug this further. – sfdcfox May 11 at 4:55
  • Thanks for responding! – Danny Vu May 11 at 5:11
  • Here is some sample code I passed: session_id, instance = SalesforceLogin(username=dev_user, password=dev_pw, security_token=dev_token, domain='test') plan = SFType('MemberPlan', session_id, instance, sf_version='47.0') plan.create( {'Name' : 'TestAPI', 'MemberId' : '001m000000xnFydAAE'}) – Danny Vu May 11 at 5:11
0

Looks like the problem is that I need to reference the actual Salesforce specified ID in the Account object and not some arbitrary ID - every Lookup or Member-Detail relationship is purely through the Salesforce ID.

So, when doing the upsert operation on the MemberPlan object, I need to reference the Account Salesforce ID referenced via the MemberId field. And I need to do the upsert operation on a unique external ID field allocated on the MemberPlan object.

sf = simple_salesforce.Salesforce(credentials)

parameters = {
'Name': 'Member Plan Testing',
'MemberId': '0012900000YyyRAAAZ',
}

sf.MemberPlan.upsert('Member_Plan_External_ID__c/0000001-H5567-007-2016-01-01', parameters)
| improve this answer | |
  • If your answer solves your issue, mark your own answer as accepted. – Florian Heer May 11 at 10:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.