0

I want to extract keys for each Salesforce object (including custom) from a Salesforce environment via the simple_salesforce python library. That is, I want a pandas dataframe that looks as follows:

object key
Account 001
Contact 003
... ...

For that, I connect via sf = simple_salesforce Salesforce(). How can I extract the desired information from this instance? Thanks for any help!

2
  • It's available as metadata of the object (type). You can call the Metadata API or use Anon Apex by combining this Q&A with this Q&A.
    – identigral
    Commented Apr 19, 2022 at 16:19
  • Seems interesting but I don't quite understand. How can I make the request to Apex via simple salesforce in my case?
    – Corram
    Commented Apr 29, 2022 at 19:37

1 Answer 1

2

The following works to create the desired table:

import pandas as pd
import simple_salesforce

sobjects = simple_salesforce.Salesforce().describe()["sobjects"]
key_prefixes = [[sf_obj["name"], sf_obj["keyPrefix"]] for sf_obj in sobjects]
key_prefixes_df = pd.DataFrame(key_prefixes, columns=["object", "key"])
print(key_prefixes_df)
2
  • Nice and concise, upvoted.
    – identigral
    Commented Apr 29, 2022 at 21:31
  • v helpful. was able to output to a text file by adding path ='keyprefixes.txt' with open(path, 'a') as f: df_string = key_prefixes_df.to_string(index=False) f.write(df_string)
    – gorav
    Commented Jun 9, 2023 at 13:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .