英文:
How to read Picklist values via Salesforce Metadata API & simple-salesforce
问题
我正在使用simple-salesforce从一些自定义对象中读取元数据:metadata = _sf.mdapi.CustomObject.read(sf_object_name)
。
一般情况下,这可以正常工作,但对于一些下拉列表字段,选项以命名的ValueSet形式返回,而不是选项列表(请参见下文)。
如何获取实际的下拉列表选项?我是否需要使用ValueSetName(例如Student_Challenge_Experience_Homesick
)调用不同的API方法?
{
'fullName': 'Experiencing_Homesickness__c',
...
...
'type': 'Picklist',
'unique': None,
'valueSet': {
'controllingField': None,
'restricted': True,
'valueSetDefinition': None,
'valueSetName': 'Student_Challenge_Experience_Homesick',
'valueSettings': [
]
},
'visibleLines': None,
'writeRequiresMasterRead': None
},
为了完整起见,某些字段确实返回带有其标签和值的下拉列表值列表:
'valueSet': {
'controllingField': None,
'restricted': None,
'valueSetDefinition': {
'sorted': False,
'value': [
{
'fullName': '3',
'color': None,
'default': False,
'description': None,
'isActive': None,
'label': '3'
},
{
'fullName': '4',
'color': None,
'default': False,
'description': None,
'isActive': None,
'label': '4'
},
{
'fullName': '5+',
'color': None,
'default': False,
'description': None,
'isActive': None,
'label': '5+'
}
]
},
'valueSetName': None,
'valueSettings': [
]
},
'visibleLines': None,
'writeRequiresMasterRead': None
},
英文:
I am using simple-salesforce to read metadata from some CustomObjects: metadata = _sf.mdapi.CustomObject.read(sf_object_name)
This generally works, EXCEPT for a number of Picklist fields: the options return as a named ValueSet instead of a list of options (see below).
How can I get the actual Picklist options? Do I need to call a different API method with the ValueSetName (ex. Student_Challenge_Experience_Homesick
)?
{
'fullName': 'Experiencing_Homesickness__c',
...
...
'type': 'Picklist',
'unique': None,
'valueSet': {
'controllingField': None,
'restricted': True,
'valueSetDefinition': None,
'valueSetName': 'Student_Challenge_Experience_Homesick',
'valueSettings': [
]
},
'visibleLines': None,
'writeRequiresMasterRead': None
},
For completeness' sake: some fields DO return a list of picklist values with their label & value:
'valueSet': {
'controllingField': None,
'restricted': None,
'valueSetDefinition': {
'sorted': False,
'value': [
{
'fullName': '3',
'color': None,
'default': False,
'description': None,
'isActive': None,
'label': '3'
},
{
'fullName': '4',
'color': None,
'default': False,
'description': None,
'isActive': None,
'label': '4'
},
{
'fullName': '5+',
'color': None,
'default': False,
'description': None,
'isActive': None,
'label': '5+'
}
]
},
'valueSetName': None,
'valueSettings': [
]
},
'visibleLines': None,
'writeRequiresMasterRead': None
},
答案1
得分: 1
听起来像是一个全局选项列表(可以在不同的对象上重复使用的选项列表定义,在一个地方维护,如果添加一个新的值,它会在所有地方都添加)。https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_globalvalueset.htm
看看是否可以使用 _sf.mdapi.GlobalValueSet.read('Student_Challenge_Experience_Homesick')
来获取它。
或者可以尝试另一种方法来查询选项列表:https://stackoverflow.com/a/76840387/313628
英文:
Sounds like a global picklist (picklist definition that can be reused, even on different objects, maintained in 1 place and if you add a new value - it adds everywhere). https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_globalvalueset.htm
See if you can pull it with _sf.mdapi.GlobalValueSet.read('Student_Challenge_Experience_Homesick')
Or alternative approach is to query the picklists: https://stackoverflow.com/a/76840387/313628
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论