Retrieve the formulas from the Salesforce Formula fields - salesforce

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.

No idea what "cdata drivers" are so hopefully some of these will point you in right direction.
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 & 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>
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'

Related

Access multiple nested TypeScript type generated from GraphQL

I need to access only the "departments" type in this large type generated from GraphQL:
export type GetCompanyChartQuery = (
{ __typename?: 'Query' }
& { generateOrgChart?: Maybe<(
{ __typename?: 'DepartmentNode' }
& Pick<DepartmentNode, 'name'>
& { manager?: Maybe<(
{ __typename?: 'EmployeeNode' }
& Pick<EmployeeNode, 'name' | 'mobilePhone'>
)>, departments?: Maybe<Array<Maybe<(
{ __typename?: 'DepartmentNode' }
& Pick<DepartmentNode, 'name' | 'depth'>
& { manager?: Maybe<(
{ __typename?: 'EmployeeNode' }
& Pick<EmployeeNode, 'name'>
)>, employees?: Maybe<Array<Maybe<(
{ __typename?: 'EmployeeNode' }
& Pick<EmployeeNode, 'imageUrl' | 'mobilePhone' | 'name' | 'position' | 'title' | 'depth'>
)>>>, departments?: Maybe<Array<Maybe<(
{ __typename?: 'DepartmentNode' }
& Pick<DepartmentNode, 'name' | 'depth'>
& { manager?: Maybe<(
{ __typename?: 'EmployeeNode' }
& Pick<EmployeeNode, 'name'>
)>, employees?: Maybe<Array<Maybe<(
{ __typename?: 'EmployeeNode' }
& Pick<EmployeeNode, 'imageUrl' | 'mobilePhone' | 'name' | 'position' | 'title' | 'depth'>
)>>> }
)>>> }
)>>> }
)> }
);
I cannot find a way around this. Pick<GetCompanyChartQuery, 'subType'> or GetCompanyChartQuery['subtype'] wont do the trick here.
I am trying to fetch data with a GraphQL query and put the response in a state like this:
const [departments, setDepartments] = useState<TheTypeINeedToAccess>();
setDepartments(data?.generateOrgChart?.departments);
But to do this I need the correct type.
Thanks in advance.
I think the issue with picking the subtypes is the optional properties. If you make the object non-nullish, TypeScript can pick out the subtype.
type Departments = Required<GetCompanyChartQuery>["generateOrgChart"]["departments"]

How do I organize the data of a json obtained from a server?

I'm making an application in unity that connects to a database and I need to organize the information obtained from it, I use the following coruotine to get the information:
private IEnumerator GetUsers(string url)
{
using (UnityWebRequest webRequest = UnityWebRequest.Get(url))
{
// Request and wait for the desired page.
yield return webRequest.SendWebRequest();
if (webRequest.isNetworkError)
{
Debug.Log(": Error: " + webRequest.error);
}
else
{
Debug.log("DATA:\n" + webRequest.downloadHandler.text);
}
}
}
and then I would like the data I receive (names, surnames, code, password ... etc) to organize it to print them or to later use them depending on what I need, thank you very much in advance.
and tried to use a serializable class to save my data but I only work with one (and when with my own data not from the server lol),I have also tried to make a vector of type people to save more than one data and it did not work either
:C or rather I did not know how to make it work
[System.Serializable]
public class People
{
public string names, surnames, cedula, password, telephone, address, code,
email;
}
[System.Serializable]
public class PeopleList
{
public People[] users;
}
public class GetSendDate : MonoBehaviour
{
private IEnumerator GetUsers(string url)
{
using (UnityWebRequest webRequest = UnityWebRequest.Get(url))
{
// Request and wait for the desired page.
yield return webRequest.SendWebRequest();
if (webRequest.isNetworkError)
{
Debug.Log(": Error: " + webRequest.error);
}
else
{
PeopleList users = new People();
string json = webRequest.downloadHandler.text;
users = JsonUtility.FromJson<PeopleList>(json);
Debug.Log(users.user[0].names);
Debug.Log(users.user[0].surnames);
Debug.Log(users.user[0].cod);
}
}
}
}
this is the response of webRequest.downloadHandler.text
[{"userID": 1, "idRole": 1, "email": "ada#gmail.com", "password": "$ 2a $ 10 $ YVXachXCaPBj9vDo.d4itO4vghtCvSMfrmeHCGJqJ6rSneM / hJsPy", "names": "Juanota Rosadita" , "surnames": "sapoton", "cedula": "123", "telefono": "789", "direccion": "147", "code": "258"}, {"idUsuario": 7, " idRole ": 1," email ":" vic#gmail.com "," password ":" $ 2a $ 10 $ JA1rszAgVK52OnWoOWDXneQcVUHwWBi2Di9o2z7kMqrWPyrjGoTnO "," names ":" victor "," Surnames ":" giron "," cedula ":" 1085 "," telefono ":" 313 "," direccion ":" yoquese "," code ":" 217 "}, {" idUsuario ": 8," idRole ": 1," email ":" juanos # gmail. com "," password ":" $ 2a $ 10 $ 6EAy2e7dXASx2MPDA3vtW.heYuM1wsaEtFmA4Lb6BD0RCTJvm / HSe "," names ":" Juanito "," Surnames ":" Alcachofa "," cedula ":" 789 "," telefono ":" 31358964 " , "address": "123", "code": "753"}]
I get the following error when I run the function in unity:
ArgumentException: JSON must represent an object type.
UnityEngine.JsonUtility.FromJson (System.String json, System.Type type) (at C:/buildslave/unity/build/Modules/JSONSerialize/Public/JsonUtility.bindings.cs:42)
UnityEngine.JsonUtility.FromJson[T] (System.String json) (at C:/buildslave/unity/build/Modules/JSONSerialize/Public/JsonUtility.bindings.cs:30)
GetSendDate+d__6.MoveNext () (at Assets/Scripts/GetSendDate.cs:73)
UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) (at C:/buildslave/unity/build/Runtime/Export/Scripting/Coroutines.cs:17)
Can you send a capture "Debug.log" of your response webRequest.downloadHandler.text?
Because it is very likely that you are trying to transform the entire response, including the header. you only have to transform the response data to json.
You can use Newton Soft Json Utility for parsing.
Just download DLL file and put it in your Assets/Plugins folders
You can download from:
https://www.nuget.org/packages/Unity.Newtonsoft.Json/
using Newtonsoft.Json;
private IEnumerator GetUsers(string url)
{
using (UnityWebRequest webRequest = UnityWebRequest.Get(url))
{
yield return webRequest.SendWebRequest();
if (webRequest.isNetworkError)
{
Debug.Log(": Error: " + webRequest.error);
}
else if (m_Request.isHttpError)
{
Debug.Log(" Server Not Responding ");
}
else
{
var response = JObject.Parse(m_Request.downloadHandler.text);
users = JsonConvert.DeserializeObject<PeopleList>(response.SelectToken("data"))
}
}
}

Syntax error in VBA SQL

Getting data from various text boxes on a form and doing an update to a SQL Server database. Here is the creation of the SQL:
Dim upDateStr As String
upDateStr = "UPDATE dbo_Master_Accounts SET dbo_Master_Accounts.FirstName = " & Chr$(34) & Me.disFirstName & Chr$(34) & ", "
upDateStr = upDateStr + "dbo_Master_Accounts.LastName = " & Chr$(34) & Me.disLastName & Chr$(34) & ", "
upDateStr = upDateStr + "dbo_Master_Accounts.Address_Line_1 = " & Chr$(34) & Me.disAddr1 & Chr$(34) & ", "
upDateStr = upDateStr + "dbo_Master_Accounts.City = " & Chr$(34) & Me.disCity & Chr$(34) & ", "
upDateStr = upDateStr + "dbo_Master_Accounts.State = " & Chr$(34) & Me.disState & Chr$(34) & ", "
upDateStr = upDateStr + "dbo_Master_Accounts.PostalCode = " & Chr$(34) & Me.disPostalCode & Chr$(34) & ", "
upDateStr = upDateStr + "dbo_Master_Accounts.Phone_Number_1 = " & Chr$(34) & Me.disHomePhone & Chr$(34) & ", "
upDateStr = upDateStr + "dbo_Master_Accounts.Phone_Number_2 = " & Chr$(34) & Me.disCellPhone & Chr$(34) & ", "
upDateStr = upDateStr + "dbo_Master_Accounts.Gender = " & Chr$(34) & Me.disGender & Chr$(34) & ", "
upDateStr = upDateStr + "dbo_Master_Accounts.Date_Of_Birth = " & Chr$(34) & Me.disDateofBirth & Chr$(34) & ", "
upDateStr = upDateStr + "dbo_Master_Accounts.Email = " & Chr$(34) & Me.disEmailAddress & Chr$(34) & ", "
upDateStr = upDateStr + "WHERE (((dbo_Master_Accounts.Master_ID) = " & Chr$(34) & Me.frmoldCardno & Chr$(34) & ""
Looked at query in immediate and all the data is there and it looks correct. Here is the immediate window.
UPDATE dbo_Master_Accounts
SET dbo_Master_Accounts.FirstName = "John",
dbo_Master_Accounts.LastName = "Handy",
dbo_Master_Accounts.Address_Line_1 = "123 From",
dbo_Master_Accounts.City = "Somewhere",
dbo_Master_Accounts.State = "IL",
dbo_Master_Accounts.PostalCode = "50310",
dbo_Master_Accounts.Phone_Number_1 = "1234567890",
dbo_Master_Accounts.Phone_Number_2 = "",
dbo_Master_Accounts.Gender = "M",
dbo_Master_Accounts.Date_Of_Birth = "02/14/1967",
dbo_Master_Accounts.Email = "me#mine.com",
WHERE (((
dbo_Master_Accounts.Master_ID
) = "000055"
But I get a syntax error that I can't see. Tried running with only first and last two line of code and get the same error.
Thanks in advance
jpl
Start by trying this to see if it works (removed comma before where, and fixed the parenthesis) and then use parameters to do it right, because this way you're open to SQL injection attacks
Dim upDateStr As String
upDateStr = "UPDATE dbo_Master_Accounts SET dbo_Master_Accounts.FirstName = '" & Me.disFirstName & "', "
upDateStr = upDateStr + "dbo_Master_Accounts.LastName = '" & Me.disLastName & "', "
upDateStr = upDateStr + "dbo_Master_Accounts.Address_Line_1 = '" & Me.disAddr1 & "', "
upDateStr = upDateStr + "dbo_Master_Accounts.City = '" & Me.disCity & "', "
upDateStr = upDateStr + "dbo_Master_Accounts.State = '" & Me.disState & "', "
upDateStr = upDateStr + "dbo_Master_Accounts.PostalCode = '" & Me.disPostalCode & "', "
upDateStr = upDateStr + "dbo_Master_Accounts.Phone_Number_1 = '" & Me.disHomePhone & "', "
upDateStr = upDateStr + "dbo_Master_Accounts.Phone_Number_2 = '" & Me.disCellPhone & "', "
upDateStr = upDateStr + "dbo_Master_Accounts.Gender = '" & Me.disGender & "', "
upDateStr = upDateStr + "dbo_Master_Accounts.Date_Of_Birth = '" & Me.disDateofBirth & "', "
upDateStr = upDateStr + "dbo_Master_Accounts.Email = '" & Me.disEmailAddress & "' "
upDateStr = upDateStr + "WHERE (dbo_Master_Accounts.Master_ID) = '" & Me.frmoldCardno & "' "

ASP JSON: Multidimensional JSON array

How should I access the "games" array within this JSON? I'm using the class from http://aspjson.com.
{
"period":[
{
"period_id":"1774",
"start_time_epoch":1431126300,
"games":[
{
"home_team":"WSH",
"away_team":"ATL"
}
]
}
]
}
Method of access:
today = date
For Each key In oJSON.data("period")
Set this = oJSON.data("period").item(key)
periodID = this.item("period_id")
periodDate = FormatDateTime(DateAdd("s", this.item("start_time_epoch"), "01/01/1970 00:00:00"),2)
----Ideally, this.item("games").item("home_team") would have worked.----
if cstr(today) = periodDate then
response.write periodID & " - " & periodDate & "<br/> - " & this.item("games").item("start_time")
end if
Next
Your JSON is not valid: http://jsonformatter.curiousconcept.com/
This would be valid:
{
"period":[
{
"period_id":"1774",
"start_time_epoch":1431126300,
"games":[
{
"home_team":"WSH",
"away_team":"ATL"
}
]
}
]
}
To access the home team you can use
Response.Write( oJSON.data("period")(0)("games")(0)("home_team"))

How do you get checkboxes to be checked in ValidForm Builder?

I need to get each of the checkboxes to be pre-selected in ValidForm Builder based on their default values if they have were selected when the record initially got written to the DB Table.
Here is my code:
$objType = $objGroup->addField('locationType', 'Location Type', VFORM_CHECK_LIST,
array('required' => true),
array('required' => 'Location Type is required'),
array(
'fieldclass' => 'vf__inlineButtons',
'tip' => (($_SESSION['auth']['tips'] && $_POST['action'] != 'delete') ? VFB_TIP_LOCATIONS_LOCATIONTYPE : NULL),
(($_POST['action'] == 'delete') ? 'fieldDisabled' : 'fieldEnabled') => (($_POST['action'] == 'delete') ? 'disabled' : 'enabled'),
'default' => $default['locationType']
)
);
$objType->addField('Destination', 'D');
$objType->addField('Sales', 'S');
$objType->addField('Pickup/Dropoff', 'P');
$objType->addField('Both, Sales & Pickup/Dropoff', 'B');
Here's my trial & error attempts to get it to work:
(1) I removed the 'default' => $default['locationType'] and added 'checked' to each $objType->addField(). So In the code above, that is all 4 of the $objType->addField()'s have the 'checked' element added to them. Result is only the last checkbox gets checked -- no success.
(2) I removed the 'default' => $default['locationType'] and added 'selected' to each $objType->addField(). So In the code above, that is all 4 of the $objType->addField()'s have the 'selected' element added to them. Result is only the last checkbox gets checked -- no success.
(3) I removed the 'default' => $default['locationType'] and added 'checked' => 'checked' to each $objType->addField(). So In the code above, that is all 4 of the $objType->addField()'s have the 'checked' => 'checked' element added to them. Result is the script generates nothing -- no success.
(4) I tried this too -- 'default' => array("D", "", "P", "") -- no success.
(5) I tried this -- 'default' => array(true, false, true, false) -- all boxes get checked -- no success.
(6) I tried this -- 'default' => array("1", "0", "1", "0") -- only the first box gets checked -- no success.
(7) I tried this -- 'default' => array(1, 0, 1, 0) -- only the first box gets checked -- no success.
I am thinking that ValidForm Builder is not ready for checkboxes.
Here is the relevant VFB code (if it helps you see where the issue is). NOTE on 2/22/2014 through my extended T&E troubleshooting I do not believe this class file is even loaded or used in the production of the HTML. Continuing to dig...:
class VF_Checkbox extends VF_Element {
public function toHtml($submitted = FALSE, $blnSimpleLayout = FALSE, $blnLabel = true, $blnDisplayErrors = true) {
$blnError = ($submitted && !$this->__validator->validate() && $blnDisplayErrors) ? TRUE : FALSE;
if (!$blnSimpleLayout) {
//*** We asume that all dynamic fields greater than 0 are never required.
if ($this->__validator->getRequired()) {
$this->setMeta("class", "vf__required");
} else {
$this->setMeta("class", "vf__optional");
}
if ($blnError) $this->setMeta("class", "vf__error");
if (!$blnLabel) $this->setMeta("class", "vf__nolabel");
// Call this right before __getMetaString();
$this->setConditionalMeta();
$strOutput = "<div{$this->__getMetaString()}>\n";
if ($blnError) $strOutput .= "<p class=\"vf__error\">{$this->__validator->getError()}</p>";
if ($this->__getValue($submitted)) {
//*** Add the "checked" attribute to the input field.
$this->setFieldMeta("checked", "checked");
} else {
//*** Remove the "checked" attribute from the input field. Just to be sure it wasn't set before.
$this->setFieldMeta("checked", null, TRUE);
}
if ($blnLabel) {
$strLabel = (!empty($this->__requiredstyle) && $this->__validator->getRequired()) ? sprintf($this->__requiredstyle, $this->__label) : $this->__label;
if (!empty($this->__label)) $strOutput .= "<label for=\"{$this->__id}\"{$this->__getLabelMetaString()}>{$strLabel}</label>\n";
}
} else {
if ($blnError) $this->setMeta("class", "vf__error");
$this->setMeta("class", "vf__multifielditem");
// Call this right before __getMetaString();
$this->setConditionalMeta();
$strOutput = "<div{$this->__getMetaString()}>\n";
if ($this->__getValue($submitted)) {
//*** Add the "checked" attribute to the input field.
$this->setFieldMeta("checked", "checked");
} else {
//*** Remove the "checked" attribute from the input field. Just to be sure it wasn't set before.
$this->setFieldMeta("checked", null, TRUE);
}
}
$strOutput .= "<input type=\"checkbox\" name=\"{$this->__name}\" id=\"{$this->__id}\"{$this->__getFieldMetaString()}/>\n";
if (!empty($this->__tip)) $strOutput .= "<small class=\"vf__tip\">{$this->__tip}</small>\n";
$strOutput .= "</div>\n";
return $strOutput;
}
public function toJS() {
$strOutput = "";
$strCheck = $this->__validator->getCheck();
$strCheck = (empty($strCheck)) ? "''" : str_replace("'", "\\'", $strCheck);
$strRequired = ($this->__validator->getRequired()) ? "true" : "false";;
$intMaxLength = ($this->__validator->getMaxLength() > 0) ? $this->__validator->getMaxLength() : "null";
$intMinLength = ($this->__validator->getMinLength() > 0) ? $this->__validator->getMinLength() : "null";
$strOutput .= "objForm.addElement('{$this->__id}', '{$this->__name}', {$strCheck}, {$strRequired}, {$intMaxLength}, {$intMinLength}, '" . addslashes($this->__validator->getFieldHint()) . "', '" . addslashes($this->__validator->getTypeError()) . "', '" . addslashes($this->__validator->getRequiredError()) . "', '" . addslashes($this->__validator->getHintError()) . "', '" . addslashes($this->__validator->getMinLengthError()) . "', '" . addslashes($this->__validator->getMaxLengthError()) . "');\n";
//*** Condition logic.
$strOutput .= $this->conditionsToJs();
return $strOutput;
}
public function getValue($intDynamicPosition = 0) {
$varValue = parent::getValue($intDynamicPosition);
return (strlen($varValue) > 0 && $varValue !== 0) ? TRUE : FALSE;
}
public function getDefault($intDynamicPosition = 0) {
return (strlen($this->__default) > 0 && $this->getValue($intDynamicPosition)) ? "on" : null;
}
}
I see where the developer recently applied a fix for your issue. You can get the revised source file at http://code.google.com/p/validformbuilder/source/list

Resources