简体   繁体   English

通过Salesforce中的SOQL查询获取选项列表值

[英]Fetch picklist values through SOQL query in Salesforce

I am using Djnago & Salesforce. 我正在使用Djnago和Salesforce。

I establish connection between them through simple-salesforce 我通过简单的salesforce建立它们之间的联系

I have created a custom picklist on Contact Object of Salesforce. 我在Salesforce的Contact Object上创建了一个自定义选项列表。

I wont to fetch all the 20 values of my picklist & display in Django. 我不会在Django中获取我的选项列表和显示的所有20个值。

I am looking for SOQL to fetch values from Salesforce. 我正在寻找SOQL来从Salesforce获取值。

sf = Salesforce(instance_url='https://test.salesforce.com', session_id='')
sf1 = Salesforce(connection parameters)
sf3 = sf1.query("SELECT Color__c FROM Contact")

sf3 will give me values set for respective Contact records. sf3将为我提供为各个联系人记录设置的值。

I want to fetch all the 20 values I have entered while creating Color__c on Contact object. 我想在Contact对象上创建Color__c时获取我输入的所有20个值。 In Apex we can do that, something like below 在Apex,我们可以做到这一点,如下所示

public class PicklistUtil { 
    public static List<Schema.PicklistEntry> getContactColor() { 
        return Contact.Color__c.getDescribe().getPicklistValues(); 
   } 
}

I am looking to do the same in Django. 我期待在Django做同样的事情。 Can someone please help? 有人可以帮忙吗?

There might be a better way, but the following should work: 可能有更好的方法,但以下应该有效:

d = sf1.Contact.describe()
for f in d['fields']:
    if f['name'] == 'Color__c':
        break
picklist = f['picklistValues']

picklist should then be a list of OrderedDicts . 然后,选项picklist应该是OrderedDicts列表。

Picklist values can be obtained also directly in choices attribute of the field as a part of Model exported by 也可以直接在字段的choices属性中获取选取列表值,作为导出模型的一部分

manage.py inspectdb --database=salesforce table_names...

with django-salesforce . django-salesforce

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM