function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
HysteresisHysteresis 

Lookup relationships with custom objects using Salesforce Python Toolkit

Hi,

 

I've been getting to grips with the Salesforce API via the Salesforce Python Toolkit recently. While I can do most of what I want to be able to do, I'm flummoxed by trying to create records containing lookup relationships. I've read a lot about using foreign keys, and making nested SObjects in Java and so on, but wondered if anyone could give me an example using the Salesforce Python Toolkit specifically.

 

For the purpose of illustration, suppose that I have two custom objects: "Project__c" and "Person__c". The project has a person associated with it using a lookup field "Associate__c" and the Person object is identified by "Ext_ID__c", 

 

This is what I've tried so far:

 

proj = sf.generateObject('Project__c')

pers = sf.generateObject('Person__c')

pers.Ext_ID__c = 'externalID'

proj.Associate__c = pers.Ext_ID__c

result = sf.create(proj)

 

In principle, the person should already exist in the database before the project is submitted. I'm not sure it this makes much of a difference.

 

I think my problem is that pers.Ext_ID__c isn't functioning as an ID, but I don't really understand why, or how to make it behave.

 

Any suggestions would be most welcome.

 

Thank you!

DanSadDanSad

A relationship field is denoted by an  __r.

You can see what the field should look like by running a describe call on your child object.