我正在寻找一种从Salesforce公式字段获取公式的方法。我们正在使用CDATA驱动程序连接到Salesforce。但是我看不到任何检索Salesforce公式的选项。
答案 0 :(得分:2)
不知道什么是“ cdata驱动程序”,所以希望其中的一些能够为您指明正确的方向。
在Apex中,您可以使用“ describe”呼叫。如果所有其他选项都失败-您可以构建一个自定义服务,将这些数据返回给您。
Schema.DescribeFieldResult dfr = Account.Address__c.getDescribe();
System.debug(dfr.getCalculatedFormula());
// BillingStreet & BR() & BillingCity & BR() & BillingPostalCode & BR() & BillingCountry & BR() & Street2__c & BR() & Street3__c
您已经标记了metadata 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'