Search code examples
pythonpysparksalesforcerestful-authenticationsimple-salesforce

how to fix 'simple_salesforce.exceptions.SalesforceResourceNotFound' error that came when describing an object Lead?


I am using simple_salesforce API client to connect to the salesforce from a pyspark shell inorder to query a list of objects. And while i was trying to describe the object to find the list of columns available i got the below error:

simple_salesforce.exceptions.SalesforceResourceNotFound: Resource source_table Not Found. Response content: [{u'errorCode': u'NOT_FOUND', u'message': u'The requested resource does not exist'}]

I observed that when i am using a variable name to store the object (table) name i am getting the resourcenotfound error. So i hard coded the object in desc statement like below: desc = sf.Lead.desc() Now this is working.

But i want a feasible solution where in i would be able to provide the object name at run time or in my case i have a list of objects. Everytime i have to loop over and describe them.

    sf = Salesforce(username='xxxxxxx', password='yyyyyy', 
         security_token='')
    source_table = "Lead"
    desc = sf.source_table.describe()

I expected that the statement execute properly, but it has thrown an error.


Solution

  • simple_salesforce's connection object (sf here) has synthetic attributes representing each available sObject. To get this dynamically with a table name, you have to use getattr(). Otherwise, you're referring to a property sf.source_table, which doesn't exist - there's no sObject called source_table.

    So you can either do

    sf.Lead.describe()
    

    or

    getattr(sf, "Lead").describe()