Search code examples
pythonsalesforcesoqlbeatboxsimple-salesforce

SOQL IN query from Python


I'm wondering if anyone knows how to format an IN query using either beatbox or simple salesforce. Example:

select id from lead where id in ('00Q3000000zLxkFEAS', '00Q3000000eODvUEAW')

In simple salesforce I have:

sf.get_sfcontacts_all(param="where Id in ({0})".format())

I have tried using a list, a tuple and a string in the format arg but keep getting a malformed request.

Any help, please?


Solution

  • using Beatbox and python 2.7 you should not get a malformed query. find the below code used without any errors:

    import beatbox
    
    "salesforceusername and password"
    username = 'xxx'
    password = "xxx"
    token    = 'xxx'
    
    """conenct and authenticate"""
    svc = beatbox.PythonClient()
    svc.login(username, password+token)
    
    """execut SOQL query"""
    res = svc.query("select id from lead where id in ('00Q3000000zLxkFEAS', '00Q3000000eODvUEAW')")
    
    """prints results in console"""
    print(res)