Search code examples
pythonpython-3.xsalesforcesalesforce-lightning

How to get metadata of Salesforce Objects using Python if the object name is dynamic?



    from salesforce_api import Salesforce
    client = * connection details*
    desc_obj = client.sobjects.Case_Details__c.describe()

I want to the object name to be dynamic as it will be an user input. Something like:-

   from salesforce_api import Salesforce
   client = * connection details*
   def extract_sffields(table_name):
       desc_obj = client.sobjects.%table_name%.describe()

where table is dynamic.


Solution

  • In Python you can use the builtins getattr and setattr to manipulate object attributes. So you can write:

    desc_obj = getattr(client.sobjects, table_name).describe()