我正在寻找一种从 Salesforce 公式字段中获取公式的方法。我们正在使用 CDATA 驱动程序连接到 Salesforce。但我没有看到任何检索 Salesforce 公式的选项。
问问题
740 次
1 回答
4
不知道什么是“cdata 驱动程序”,因此希望其中一些能够为您指明正确的方向。
在 Apex 中,您可以使用“描述”调用。如果所有其他选项都失败 - 您可以构建一个自定义服务,将这些数据返回给您。
Schema.DescribeFieldResult dfr = Account.Address__c.getDescribe();
System.debug(dfr.getCalculatedFormula());
// BillingStreet & BR() & BillingCity & BR() & BillingPostalCode & BR() & BillingCountry & BR() & Street2__c & BR() & Street3__c
您已经标记了元数据 API,因此如果您真的使用它 - 类似的信息应该在其中可用。
<CustomField>
<fullName>Address__c</fullName>
<externalId>false</externalId>
<formula>BillingStreet & BR() & BillingCity & BR() & BillingPostalCode & BR() & BillingCountry & BR() & Street2__c & BR() & Street3__c</formula>
<formulaTreatBlanksAs>BlankAsZero</formulaTreatBlanksAs>
<label>Address</label>
<required>false</required>
<trackHistory>false</trackHistory>
<type>Text</type>
<unique>false</unique>
</CustomField>
在REST API中类似,调用/services/data/v48.0/sobjects/Account/describe
将返回(以及其他)
{
"aggregatable" : true,
"aiPredictionField" : false,
"autoNumber" : false,
"byteLength" : 3900,
"calculated" : true,
"calculatedFormula" : "BillingStreet & BR() & BillingCity & BR() & BillingPostalCode & BR() & BillingCountry & BR() & Street2__c & BR() & Street3__c",
"cascadeDelete" : false,
(...)
"formulaTreatNullNumberAsZero" : true,
"groupable" : false,
"highScaleNumber" : false,
"htmlFormatted" : true,
"idLookup" : false,
"inlineHelpText" : null,
"label" : "Address",
"length" : 1300,
"mask" : null,
"maskType" : null,
"name" : "Address__c",
(...)
"type" : "string",
"unique" : false,
"updateable" : false,
"writeRequiresMasterRead" : false
}
最后是Tooling API,您可以在其中查询元数据,就像查询普通数据库表一样。但是您需要的核心将隐藏在您必须解析的 JSON 字段中。如果您的工具是一些 ETL - 检查它是否可以查询FieldDefinition
表。
/services/data/v48.0/tooling/query?q=SELECT+Metadata+FROM+FieldDefinition+WHERE+EntityDefinitionId+=+'Account'+AND+QualifiedApiName+=+'Address__c'
于 2020-05-28T08:27:08.767 回答