Create Custom field in Salesforce using Tooling API - api

I am trying to create custom field using Tooling API in Salesforce. First to check Tooling API, I tried using workbench but it is showing following error:
JSON Parser Error:
message: Cannot deserialize instance of complexvalue from VALUE_STRING value text or request may be missing a required field at [line:5, column:25]
errorCode: JSON_PARSER_ERROR
Following is the JSON body I am using:
{
"DeveloperName" : "CusField",
"Metadata":
{
"type" : "text",
"description" : "test",
"inlineHelpText" : "testhelp",
"label" : "cus Field",
"required" : false,
"precision" : null,
"length" : 255,
"unique" : false,
"externalId" : false,
"trackHistory" : false
},
"TableEnumOrId" : "Account",
"ManageableState" : "installed"
}
Please let me know what is wrong with body?
Thanks in Advance.

There are a few things wrong with the body.
Remove ManageableState
Do not include DeveloperName and TableEnumOrId, instead, use FullName as shown below
Capitalize the field type Text
Here's a working post body:
{
"FullName" : "Account.CusField__c",
"Metadata": {
"type" : "Text",
"description" : "test",
"inlineHelpText" : "testhelp",
"label" : "cus Field",
"required" : false,
"precision" : null,
"length" : 255,
"unique" : false,
"externalId" : false,
"trackHistory" : false
}
}

Related

Problem requesting additional fields in REST2 api

I am using the RT::Extension::REST2 api (https://metacpan.org/pod/RT::Extension::REST2) for a project and i am having a problem requesting additional fields in some requests.
I need to make a TicketSQL query and for performance reasons i am trying to obtain all the information of a ticket with something like /REST/2.0/ticket/8?fields=Requestor and i get something like
"Requestor": [
{
"_url" : "http://<>/REST/2.0/user/example#example.com",
"id" : "example#example.com",
"type" : "user"
},
{
"_url" : "http://<>/REST/2.0/user/example#example.com",
"id" : "example#example.com",
"type" : "user"
}
]
Notice it is a List of dictionaries, so when i try to do /REST/2.0/ticket/8?fields[Requestor]=Name the field Name does not appear on the dictionaries inside the list.
So i am trying to get something like this:
"Requestor": [
{
"_url" : "http://<>/REST/2.0/user/example#example.com",
"id" : "example#example.com",
"type" : "user",
"Name" : "user20",
},
{
"_url" : "http://<>/REST/2.0/user/example#example.com",
"id" : "example#example.com",
"type" : "user",
"Name" : "user20",
}
]
Is there any way i can do this ?
Thank you for your help!

Get from jenkins list of nodes by label - by REST API

I need to GET list of nodes that contains certain label.
I know how to do that by getting entire nodes list by using Jenkins REST API and then getting node by node also REST API and checking its labels - but its to many API calls.
I also can create some job that writing to some place nodes list by label as parameter - but its bad way as Jenkins job that triggered remotely have no return value and I cant know it finished and will need read results from some other place the job saved it there.
I need some way that by one API call I will get nodes list contains a given label.
You can run a single API call to <JENKINS_URL>/computer/api/json (or <JENKINS_URL>/computer/api/python for a python api) which return a list of all nodes and their properties.
One of the properties is the label - so just go over all nodes and extract the ones that contain your needed label.
Here is an example for the returned object:
{
"_class" : "hudson.model.ComputerSet",
"busyExecutors" : 0,
"computer" : [
{
"_class" : "hudson.model.Hudson$MasterComputer",
"actions" : [
],
"assignedLabels" : [
{
"name" : "built-in"
}
],
"description" : "the Jenkins controller's built-in node",
"displayName" : "Built-In Node",
"executors" : [
{
},
{
}
],
"icon" : "symbol-computer",
"iconClassName" : "symbol-computer",
"idle" : true,
"jnlpAgent" : false,
"launchSupported" : true,
"loadStatistics" : {
"_class" : "hudson.model.Label$1"
},
"manualLaunchAllowed" : true,
"monitorData" : {
"hudson.node_monitors.SwapSpaceMonitor" : {
"_class" : "hudson.node_monitors.SwapSpaceMonitor$MemoryUsage2",
"availablePhysicalMemory" : 6938730496,
"availableSwapSpace" : 6906019840,
"totalPhysicalMemory" : 16885276672,
"totalSwapSpace" : 21046026240
},
"hudson.node_monitors.TemporarySpaceMonitor" : {
"_class" : "hudson.node_monitors.DiskSpaceMonitorDescriptor$DiskSpace",
"timestamp" : 1653907906021,
"path" : "C:\\Windows\\Temp",
"size" : 426696622080
},
"hudson.node_monitors.DiskSpaceMonitor" : {
"_class" : "hudson.node_monitors.DiskSpaceMonitorDescriptor$DiskSpace",
"timestamp" : 1653907905929,
"path" : "C:\\ProgramData\\Jenkins\\.jenkins",
"size" : 426696622080
},
"hudson.node_monitors.ArchitectureMonitor" : "Windows 10 (amd64)",
"hudson.node_monitors.ResponseTimeMonitor" : {
"_class" : "hudson.node_monitors.ResponseTimeMonitor$Data",
"timestamp" : 1653907905941,
"average" : 0
},
"hudson.node_monitors.ClockMonitor" : {
"_class" : "hudson.util.ClockDifference",
"diff" : 0
}
},
"numExecutors" : 2,
"offline" : false,
"offlineCause" : null,
"offlineCauseReason" : "",
"oneOffExecutors" : [
],
"temporarilyOffline" : false
}
],
"displayName" : "Nodes",
"totalExecutors" : 2
}
You are interested in the assignedLabels object - notice that it can contain multiple labels.

How to use i18next-node-mongodb-backend?

Did anyone knows how to store data in mongoDB to be used with https://github.com/gian788/i18next-node-mongodb-backend. Tried couple of things and its not translating keys.
Here is how I am storing my data in mongo
{"en" : { "translation" : { "FirstName" : "First Name", "LastName" : "Lastwq Name" } } }
While printing it always prints key with error
i18next::translator: missingKey en translation FirstName FirstName
Any help?
The format is the following :
{
"_id" : ObjectId("581f3645caa6b31c074dd91c"),
"language" : "en",
"namespace" : "translation",
"data" : {
"FirstName" : "First Name",
"LastName" : "Lastwq Name"
}
}
Obviously you can change the namespace in the init options

How do I set up my json schema structure

I'm trying to figure out how a json schema should be implemented (as standardized as possible).
I have noticed that if I define a schema for a form using the v4 draft, I cannot voice the requirements my project has. So I created a schema that uses the v4 schema ("$schema": "http://json-schema.org/draft-04/schema#"), and gave it a custom id for the project, lets call it projectschema#. This schema validates, so all is good standard-wise. I have added two values to the type enum.
I then use this schema as $schema for another schema that describes form properties and validations, the formschema#. This schema too validates, this time against the projectschema#.
Now, as documented on www.json-schema.org, there's also a hyper-schema which allows the definition of links. Useful, as I can define where to POST the form to, or even where to get valueSets to use in the form (i.e. a rest service to get a list of user titles).
However, the v4 schema itself does not support links. I see how the v4 hyper-schema draft does support links, and is referencing the v4 schema draft, but I cannot figure out how to implement the hyper-schema, which probably means I'm missing some fundamental part of the 'how to use and implement json schema' knowledge.
I found the following on http://json-schema.org/latest/json-schema-hypermedia.html:
JSON Schema is a JSON based format for defining the structure of JSON data. This document specifies hyperlink- and hypermedia-related keywords of JSON Schema.
The term JSON Hyper-Schema is used to refer to a JSON Schema that uses these keywords.
If the draft hyper-schema uses the draft schema keywords, then why is the 'links' keyword nowhere to be found in the schema?
Is my (or any) custom schema actually a hyper schema? And if so, is anything that implements a (custom or draft) json schema called a hyper schema?
I could fire off a hundred questions. Main question: what is the relation between a Schema and a Hyper Schema, and how should I implement a schema for a form that needs more types than defined in the v4 draft?
Sorry for the length of this answer. Hopefully it's helpful.
I too struggled to understand how to validate a particular link in Hyper-Schema so I implemented each link as a base JSON Schema then tied each link together with a Hyper-Schema.
Definitions (definitions.json):
{
"$schema" : "http://json-schema.org/schema#",
"definitions" : {
"id" : {
"type" : "integer",
"minimum" : 1,
"exclusiveMinimum" : false
},
"foreign_key_id" : {
"$ref" : "#/definitions/id"
},
"season_name" : {
"type" : "string",
"minLength" : 1,
"maxLength" : 1,
"pattern" : "^[A-T]{1,1}$"
},
"currency" : {
"type" : "integer"
},
"shares" : {
"type" : "integer"
},
"username" : {
"type" : "string",
"minLength" : 1,
"maxLength" : 19,
"pattern" : "^[^ ]{1,19}$"
},
"name" : {
"type" : "string",
"minLength" : 1,
"maxLength" : 64,
"pattern" : "^[A-Za-z0-9][A-Za-z0-9_\\- ]*$"
},
"email" : {
"type" : "string",
"format" : "email"
},
"timestamp" : {
"type" : "string",
"format" : "date-time"
}
}
}
Base object schema:
{
"$schema" : "http://json-schema.org/schema#",
"type" : "object",
"properties" : {
"id" : { "$ref" : "definitions.json#/definitions/id" },
"season_name" : { "$ref" : "definitions.json#/definitions/season_name" },
"user_id" : { "$ref" : "definitions.json#/definitions/foreign_key_id" },
"coins" : { "$ref" : "definitions.json#/definitions/currency" },
"bonus_coins" : { "$ref" : "definitions.json#/definitions/currency" },
"created_at" : { "$ref" : "definitions.json#/definitions/timestamp" },
"updated_at" : { "$ref" : "definitions.json#/definitions/timestamp" }
},
"required" : [
"id",
"season_name",
"user_id",
"coins",
"bonus_coins",
"created_at",
"updated_at"
],
"additionalProperties" : false
}
POST schema (account_request_post.json):
{
"$schema" : "http://json-schema.org/schema#",
"type" : "object",
"properties" : {
"season_name" : { "$ref" : "definitions.json#/definitions/season_name" },
"user_id" : { "$ref" : "definitions.json#/definitions/foreign_key_id" }
},
"required" : [
"season_name",
"user_id"
],
"additionalProperties" : false
}
Hyper Schema:
{
"$schema" : "http://json-schema.org/schema#",
"type" : "object",
"links" : [
{
"description" : "Create a new account.",
"href" : "accounts",
"method" : "POST",
"rel" : "create",
"title" : "Create",
"schema" : { "$ref" : "account_request_post.json#" }
},
{
"description" : "List accounts.",
"href" : "accounts",
"method" : "GET",
"rel" : "index",
"title" : "List"
}
]
}
Json hyper-schema is a subset of Json-schema standard dedicated to hyperlink and hypermedia keywords and rules.
The "links" keyword is defined in the hyper-schema section of the draft. Indeed it is a part of json-schema (despite it is defined in a special draft section)
If your are defining an API interface, it is likely you want to use hyper-schema. If you are just defining validation contracts, plain Json-schema keywords are enough.

remove specific object from MongoDB collection

I'm trying to remove from MongoDB collection an object (not document) that meets specific value condition, in this case - "Accessible" : "null" - while keeping other instances of this objects. I tried db.collection.update({}, {$unset: { "Accessible":"null"}}, false, true) but it removed all objects with "Accessible" key.Thanks in advance
My MongoDB collection before update
{
"_id" : ObjectId("52e5f09e8f3d99e1046abccc"),
"Name" : "Skyline",
"Accessible" : "Y"
}
{
"_id" : ObjectId("52e5f09e8f3d99e1046abccd"),
"Name" : "Highland",
"Accessible" : "null"
}
Desired result:
{
"_id" : ObjectId("52e5f09e8f3d99e1046abccc"),
"Name" : "Skyline",
"Accessible" : "Y"
}
{
"_id" : ObjectId("52e5f09e8f3d99e1046abccd"),
"Name" : "Highland"
}
You need to first identify the documents you wish to update and then unset that specific field:
db.collection.update(
{"Accessible" : "null"},
{$unset: { "Accessible" : ""}},
{ multi: true }
)
Further documentation on $unset operator:
http://docs.mongodb.org/manual/reference/operator/update/unset/