Retrieve the formulas from the Salesforce Formula fields

0 votes
I am looking for a way to get the formulas from Salesforce Formula fields. We are using the CDATA Drivers to connect to Salesforce. But I am not seeing any option to retrieve the Salesforce formulas.
Mar 2 in SalesForce by surbhi
• 3,810 points
59 views

1 answer to this question.

0 votes

In Apex you can use "describe" calls. If all other options fail - you could build a custom service that returns this data to you.

Schema.DescribeFieldResult dfr = Account.Address__c.getDescribe();
System.debug(dfr.getCalculatedFormula());
// BillingStreet & BR() & BillingCity & BR() &  BillingPostalCode & BR() &  BillingCountry & BR() &  Street2__c & BR() & Street3__c

You've tagged metadata API so if you really use that - similar info should be available in it.

<CustomField>
    <fullName>Address__c</fullName>
    <externalId>false</externalId>
    <formula>BillingStreet &amp; BR() &amp; BillingCity &amp; BR() &amp;  BillingPostalCode &amp; BR() &amp;  BillingCountry &amp; BR() &amp;  Street2__c &amp; BR() &amp; Street3__c</formula>
    <formulaTreatBlanksAs>BlankAsZero</formulaTreatBlanksAs>
    <label>Address</label>
    <required>false</required>
    <trackHistory>false</trackHistory>
    <type>Text</type>
    <unique>false</unique>
</CustomField>

In REST API it's similar, a call to /services/data/v48.0/sobjects/Account/describe will return (among others)

{
    "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
  }

And finally there's Tooling API where you can query the metadata like you'd query normal database tables. But the core of what you need will be hidden in a JSON field you'd have to parse. If your tool is some ETL - check if it can query FieldDefinition table.

/services/data/v48.0/tooling/query?q=SELECT+Metadata+FROM+FieldDefinition+WHERE+EntityDefinitionId+=+'Account'+AND+QualifiedApiName+=+'Address__c'

answered Mar 2 by surbhi
• 3,810 points

Related Questions In SalesForce

0 votes
1 answer

Apex (Salesforce) read json from response and store it in a string variable

String jsonStr = '{ "oktaToken":"eyJraWQiOiIyNlN1NHFMNnVVZTVJX2M5X2Z3WmZvX09ON0dNUHRtQzlEeHFsTGplLS00IiwiYWxnIjoiUlMyNTYifQ.eyJ2ZXIiOjEsImp0aSI6IkFULlVINmdIOF9BcWJ" }'; Map<String, String> ...READ MORE

answered Mar 3 in SalesForce by CoolCoder
• 4,360 points
351 views
0 votes
0 answers

Apex (Salesforce) read json from response and store it in a string variable

I am trying to hit a API ...READ MORE

Mar 4 in SalesForce by surbhi
• 3,810 points
84 views
0 votes
1 answer

In Salesforce what is the difference between Page Layouts and Visual force Pages?

A built-in standard mechanism for displaying information ...READ MORE

answered Mar 9 in SalesForce by CoolCoder
• 4,360 points
30 views
0 votes
1 answer

In Salesforce Whats the difference between Page Layouts and Visual force Pages?

A built-in standard mechanism for displaying information ...READ MORE

answered Mar 9 in SalesForce by CoolCoder
• 4,360 points
34 views
+2 votes
2 answers

Salesforce Interview questions

Here are some questions very important for ...READ MORE

answered Jan 11, 2019 in Career Counselling by Suresh
• 720 points
1,829 views
0 votes
1 answer

How to connect to salesforce from tableau?

Hi, follow these steps to connect to Salesforce: 1. ...READ MORE

answered Mar 25, 2019 in Tableau by Cherukuri
• 33,010 points
287 views
0 votes
1 answer

Power BI - Salesforce

Hi, Follow below steps: 1. Go to Data source. 2. ...READ MORE

answered Mar 25, 2019 in Power BI by Cherukuri
• 33,010 points
173 views
0 votes
1 answer

What is the best training for Salesforce ADM-201 Exam?

Hi @Vardhan, I took Edureka's Salesforce Training that covers all ...READ MORE

answered Jun 3, 2021 in Others by Jaya
• 140 points

edited Dec 22, 2021 by Soumya 202 views
0 votes
1 answer

Salesforce Formula Text Value Based on Custom Field Picklist Value

You should update the fields using the ...READ MORE

answered Mar 2 in SalesForce by surbhi
• 3,810 points
135 views
0 votes
1 answer

Salesforce Test Class - System.NullPointerException: Attempt to de-reference a null object

Because testAccount.account is never set, it is ...READ MORE

answered Mar 2 in SalesForce by surbhi
• 3,810 points
114 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP