1

I am using the Python Simple-Salesforce Library for bulk insert and updating records.

I want to create one method in which I pass the Sobject API name and then at run time have it insert/update records to that specific objects table in the Salesforce database.

Below are two examples of what I am literally looking to achieve.

Example1:

Sobject_Name__c = 'Case'
sf.bulk.Sobject_Name__c.insert(bulk_data, batch_size, use_serial)

Example2:

Sobject_Name__c = 'Custom_Object__c'
sf.bulk.Sobject_Name__c.insert(bulk_data, batch_size, use_serial)

Is there a way to dynamically insert/update objects at run time using the Simple-Salesforce Library?

1 Answer 1

1

Use the Python eval statement to convert string to a method call.

See below code:

function_name = f"sf.bulk.{object_name}.insert"

response = eval(function_name)(bulk_data, batch_size, use_serial)

return response

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.