Back

Explore Courses Blog Tutorials Interview Questions
0 votes
3 views
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:

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?

1 Answer

0 votes
by (32.1k points)
edited by

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.

To learn in-depth about Workflow in Salesforce, sign up for industry-based Salesforce Training!

Browse Categories

...