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

How to get all custom labels information which is used in apex page?

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

{!$Label.MyCustomLabel}

。那么我可以通过rest api.

获取关于MyCustomLabel的信息吗

如有任何指导,我们将不胜感激。谢谢

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

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

1., listMetadata, 将 org-id 替换为您的组织 ID,并将 session-id 替换为您的会话 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>' 

尝试: 1 - 从控制台激活工具 api 2 - 查询:

Select Id, name, masterlabel, ManageableState, Value 
FROM ExternalString