0 votes
1 view
in Salesforce by (11.9k points)
edited by

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


Is there no way to do something like this?


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?

1 Answer

0 votes
by (31.6k points)

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

get_attr is used to return the value of SFType(name, self.session_id, self.sf_instance, self.sf_version, self.proxies).

This can be done in the following way:

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 this is useful.

Welcome to Intellipaat Community. Get your technical queries answered by top developers !