How to declare variable 'Id' from query in Python?

Viewed 31
print(sf.query(query=LVGisVda))

Console:

OrderedDict([('totalSize', 1), ('done', True), ('records', [OrderedDict([('attributes', OrderedDict([('type', 'WWWW_AC_2__DU_ListedVehicle__c'), ('url', '/services/data/v52.0/sobjects/WWWW_AC_2__DU_ListedVehicle__c/a019E00000EAsqzQAD')])), ('Id', '**a019E00000EAsqzQAD**')])])])

How to declare a019E00000EAsqzQAD as variable?

1 Answers

Here you can understand better what is an OrderedDict.
But you can get the value wanted using:

ordered_dict = sf.query(query=LVGisVda)
id_value = ordered_dict['records'][0]['Id']

In case you want to handle all data inside ordered_dict['records'] you should consider loop through it, like:

ordered_dict = sf.query(query=LVGisVda)
ids = [element['Id'] for element in ordered_dict['records']]
Related