如何获取顶点页面中使用的所有自定义标签信息?

问题描述 投票:1回答:1

我想通过rest API获取所有自定义标签。我在顶点页面中使用了自定义标签

{!$ Label.MyCustomLabel}

。所以我可以通过rest api获取有关MyCustomLabel的信息。

任何指导将不胜感激。谢谢

salesforce visualforce salesforce-lightning salesforce-communities
1个回答
1
投票

从组织中获取自定义标签并不是一种简单的方法。 CustomLabel / ExternalString对象不可查询,其余api的services/data/v43.0/nouns部分也不包含它们。

现在从Salesforce获取自定义标签的唯一方法是阅读元数据。最快的方法可能是使用同步listMetadatareadMetadata调用。这使用SOAP api,因此这里涉及一些XML。

1.,listMetadata,用您的组织ID替换org-id,并用您的会话ID替换session-id

curl \
-H 'Content-Type: text/xml' \
-H 'SOAPAction: ""' \
https://ap4.salesforce.com/services/Soap/m/38.0/org-id \
-d '<?xml version="1.0" encoding="utf-8"?><env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"><env:Header><n1:SessionHeader xmlns:n1="http://soap.sforce.com/2006/04/metadata"><n1:sessionId>session-id</n1:sessionId></n1:SessionHeader></env:Header><env:Body><n1:listMetadata xmlns:n1="http://soap.sforce.com/2006/04/metadata"><n1:queries><n1:type type="xsd:string">CustomLabel</n1:type></n1:queries></n1:listMetadata></env:Body></env:Envelope>'

2.,拉出<fullName>标签内的所有自定义标签名称

3.,readMetadata,将org-id替换为您的组织ID,将session-id替换为您的会话ID,并将custom-label-name替换为自定义标签的名称。

curl \
-H 'Content-Type: text/xml' \
-H 'SOAPAction: ""' \
https://ap4.salesforce.com/services/Soap/m/38.0/org-id \
-d '<?xml version="1.0" encoding="utf-8"?><env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"><env:Header><n1:SessionHeader xmlns:n1="http://soap.sforce.com/2006/04/metadata"><n1:sessionId>session-id</n1:sessionId></n1:SessionHeader></env:Header><env:Body><n1:readMetadata xmlns:n1="http://soap.sforce.com/2006/04/metadata"><n1:type type="xsd:string">CustomLabel</n1:type><n1:fullNames type="xsd:string">custom-label-name</n1:fullNames><n1:fullNames type="xsd:string">custom-label-name</n1:fullNames></n1:readMetadata></env:Body></env:Envelope>' 
© www.soinside.com 2019 - 2024. All rights reserved.