heroku / salesforce-bulk

Python interface to the Salesforce.com Bulk API
MIT License
207 stars 154 forks source link

upsert on a reference field #112

Open haileyneorsd opened 1 year ago

haileyneorsd commented 1 year ago

Hello. Does anybody know how to upsert on a reference field?

Below on line#2 I create the SF job where I upsert to the 'Premisec' object, and upsert using the 'Premise_ID__c' field. The 'Premise_IDc' field is a reference field in the SF object. I am receiving the error: "Premise_ID__c not specified" .

Would appreciate if anybody has some knowledge around this. Thanks.

        print("Creating SF job")
        job = sf.create_upsert_job(object_name="Premise__c", external_id_name="Premise_ID__c", contentType='JSON', pk_chunking=True)

        #put records into data_holder using .txt file generated by previous componenet
        premise = []
        f = open('premise_one_record.txt', 'r')
        next(f)
        for line in f:
            #print(line)    
            premise.append(line.split('|'))

        #for each row in db, append dicts{} of records to data_holder[]
        for record in premise:
            data_holder.append({'Premise_Surrogate_ID__c':record[0],
                        "Unique_Premise__r": {"Premise_ID__c":record[1]},
                        'Name':record[2], 
                        'Premise_Address_Full__c':record[3],
                        'Premise_Address_Str1__c':record[4],
                        'Premise_Address_Str2__c':record[5],
                        'Premise_City__c':record[6],
                        'Premise_Postal__c':record[7],
                        'Premise_State__c':record[8],
                        'CityCode__c':record[9],
                        'Parcel_ID__c':record[10],
                        'Parent_Parcel_ID__c':record[11],
                        'Latitude__c':record[12],
                        'Longitude__c':record[13],
                        'SW_ERU__c':record[14],
                        'SW_Tier__c':record[15],
                        'SW_Community_Name__c':record[16],
                        'SW_Only_Flag__c':record[17],
                        'CWD_Account_Number__c':record[18],
                        "Customer_ID__r":{'Customer_ID__c':record[19]},
                        'Premise_Has_Certification__c':record[20]                
                        })

        f.close()