5

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?

davejagoda
  • 2,420
  • 1
  • 20
  • 27
logeyg
  • 549
  • 2
  • 8
  • 31

1 Answers1

5

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.

RD3
  • 1,089
  • 10
  • 24