Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing salesforce metadata using python simple-salesforce

When reading the simple-salesforce docs, it only shows accessing object metadata using hard-coded methods like such:

sf.Contact.metadata()

Is there no way to do something like this?

sf["Contact"].metadata()

I want to loop through a list of objects and retrieve all these objects fields, but it seems like this isn't possible due to the limitation seen above.

for obj in objects:
    fields = [x["name"] for x in sf[obj].describe()["fields"]]
    # processing for each object

Is there any way to access object metadata using a string parameter, instead of a hard-coded value?

like image 303
logeyg Avatar asked Oct 19 '22 02:10

logeyg


1 Answers

The sf. interface is actually call to the the get_attr method in the Salesforce class.

get_attr returns the value of SFType(name, self.session_id, self.sf_instance, self.sf_version, self.proxies).

You could do what you would like with the following:

from simple_salesforce import SFType
....
sf_object = ['Case', 'Contact', 'Account', 'Custom1__c', 'Custom2__c']
for each in sf_object:
    SFType(each, sf.session_id, sf.sf_instance, sf.sf_version, sf.proxies).metadata()

Hope that helps.

like image 82
Rob Davis Avatar answered Oct 29 '22 17:10

Rob Davis