使用Python更新Salesforce中的自定义选项列表
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了使用Python更新Salesforce中的自定义选项列表,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3356字,纯文字阅读大概需要5分钟。
内容图文
![使用Python更新Salesforce中的自定义选项列表](/upload/InfoBanner/zyjiaocheng/703/4e2aee35dd464c65b22bb3c5c0e552d3.jpg)
目前我正在尝试将值添加到我们在Salesforce中使用的自定义选项列表中.
目前,经过多天的尝试,我能够创建一个新的自定义选项列表,如下所示:
url2 = "https://INSTANCE.salesforce.com/services/Soap/m/45.0/ORGID"
headers2 = {'content-type': 'text/xml; charset=utf-8', "SOAPAction":"POST"}
body2 = """<?xml version="1.0" encoding="utf-8" ?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:apex="http://soap.sforce.com/2006/08/apex"
xmlns:cmd="http://soap.sforce.com/2006/04/metadata"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Header>
<cmd:SessionHeader>
<cmd:sessionId>{0}</cmd:sessionId>
</cmd:SessionHeader>
</soapenv:Header>
<soapenv:Body>
<create xmlns="http://soap.sforce.com/2006/04/metadata">
<metadata xsi:type="CustomField">
<fullName>Case.verursacht_durch_MA2__c</fullName>
<label>verursacht_durch_MA2</label>
<type>Picklist</type>
<valueSet>
<restricted>true</restricted>
<valueSetDefinition>
<sorted>false</sorted>
<value>
<fullName>ValueTest</fullName>
<default>false</default>
<label>ValueTest</label>
</value>
</valueSetDefinition>
</valueSet>
</metadata>
</create>
</soapenv:Body>
</soapenv:Envelope>""".format(sessionId)
response2 = requests.post(url2,data=body2,headers=headers2)
现在我尝试使用xml更新现有选项列表中的值.
但是当我试图用更新标签替换create标签时,它告诉我像“fullName”,“label”等标签在这个位置无效.
任何帮助将非常感激!
解决方法:
经过几天的努力,我终于找到了更新Salesforce现有选项列表的方法!
使用这个 – > https://github.com/gbarger/PySalesforce
import sys, os
sys.path.append(os.path.dirname(os.path.realpath(__file__)) + '/PySalesforce')
import pysalesforce
# IS_PRODUCTION is a bool value
# set it to False when working on sandbox
login = pysalesforce.Authentication.get_oauth_login("USERNAME", "passwordSECRETKEY",
"CLIENT_ID",
"CLIENT_SECRET", IS_PRODUCTION)
# Instance Url is inside the login variable, typically you only need to append
# services/Soap/m/38.0/ORGID
# 38.0 is the used api version
metadataUrl = 'METADATA_URL'
# Here im getting the current picklist which is a custom picklist used in our Cases
# The picklist im editing is called verursacht_durch_MA2 and you need to append __c because its a custom field
getPicklist = pysalesforce.Metadata.read_metadata(metadata_type="CustomField", full_names="Case.verursacht_durch_MA2__c",
session_id=login['access_token'], metadata_url=metadataUrl,
client_name="Client-Name")
# Here im changing some names inside the existing picklist.
# Values can be added when appending to CustomField['valueSet']['valueSetDefinition']['value']
# Values look like this:
# {'fullName': 'test456', 'color': None, 'default': False, 'description': None, 'isActive': True, 'label': 'test456label'}
CustomField = getPicklist[0]
CustomField['valueSet']['valueSetDefinition']['value'][0]['fullName']="test456"
CustomField['valueSet']['valueSetDefinition']['value'][0]['label']="test456label"
CustomField['valueSet']['valueSetDefinition']['value'][0]['isActive']=True
# Here im updating the picklist, if all_or_none is True it will rollback all changes if any error occurs,
# if its set to False it will keep all already made changes on error
response = pysalesforce.Metadata.update_metadata(metadata_list=[CustomField], client_name="Client-Name", session_id=login['access_token'],
metadata_url=metadataUrl, all_or_none=False)
内容总结
以上是互联网集市为您收集整理的使用Python更新Salesforce中的自定义选项列表全部内容,希望文章能够帮你解决使用Python更新Salesforce中的自定义选项列表所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。