0

Trying to figure out a way if I can use this API to get retrieve data if I only have the ID (don’t know if it is a task or a contact, etc.)

I think no but just want to confirm.

0

Simple-Salesforce appears to use the REST API, but it doesn't have a method to call the UI-API at this point (you'd have to build a method in for that).

You can use the User Interface API having just an ID:

/services/data/v43.0/ui-api/record-ui/XXXXXXXXXXXXXXX

It will return the layout, values, record type mapping, etc for the record.

1
  • There is a generic restful() method available that can be given an arbitrary REST endpoint.
    – David Reed
    Aug 15 '18 at 22:28
0

simple_salesforce has a convenience method to obtain the global describe results. You can walk through that data structure to build a dictionary of object key prefix to API name, and use that dictionary to figure out what type of ID you are holding.

Below sf is your simple_salesforce.Salesforce connection object.

key_prefix_map = {}
for sobj in sf.describe()['sobjects']:
    if sobj['keyPrefix'] is not None:
        key_prefix_map[sobj['keyPrefix']] = sobj['name']

or we can one-liner it with a dict comprehension:

key_prefix_map = { sobj['keyPrefix']: sobj['name'] for sobj in sf.describe()['sobjects'] if sobj['keyPrefix'] is not None }

Then you can look up the first three characters of your Id in that dict to get the API name of the sObject to which it belongs, from which you can construct a simple_salesforce proxy object:

proxy = sf.SFType(key_prefix_map[my_id[:3]])

Against that proxy, you can do retrieves, updates, etc., just like you normally would with simple_salesforce; it's just like holding a reference to sf.Contact or sf.Account. So you could do

data = proxy.get()

to retrieve the record, or do

proxy.update(my_id, {'LastName': 'Test', 'FirstName': 'John'})

to perform an update. Naturally, you can also template out a Dynamic SOQL query, and you don't need to get the proxy object to do so:

sf.query('SELECT Id FROM ' + key_prefix_map[my_id[:3]] + ' WHERE Id = ' + my_id)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.