Access Salesforce metadata using simple python-salesforce

When reading simple-salesforce documents, it only shows access to object metadata using hardcoded methods such as:

sf.Contact.metadata()

Is there no way to do something like this?

sf["Contact"].metadata()

I want to iterate over the list of objects and get all these fields of objects, but it seems that this is not possible due to the limitation described above.

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

Is there a way to access object metadata using a string parameter rather than a hard-coded value?

+4
source share
1 answer

sf. the interface actually calls the get_attr method in the Salesforce class.

get_attr SFType (name, self.session_id, self.sf_instance, self.sf_version, self.proxies).

, , :

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()

, .

0

Source: https://habr.com/ru/post/1608363/


All Articles