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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With