How to generate custom _id values for CLOUDANT database? - cloudant

I am trying to insert Employee record in cloudant using their Java API.
When I insert the record, Cloudant is generating its own _ID automatically. I would like to control generation of this _ID field as well.
I searched the API, but couldn't find anything like a SEQUENCE in RDBMS. Can someone give hint on how to achieve this?

Using the Cloudant Java library, use the save method to allow you to specify the id of your documents:
https://github.com/cloudant/java-cloudant#comcloudantclientapidatabasesaveobjectwritequorum
The underlying HTTP API is documented here:
https://docs.cloudant.com/document.html#documentCreate

While creating your document if you pass _id within your JSON it will be created as per that. If _id is not present then it will be created automatically.
For example, This will create _id as you provide (AAA1)
{
"_id":"AAA1",
"fname":"Dimitry",
"country":"India"
}
and this will generate _id automatically
{
"fname":"Dimitry",
"country":"India"
}

Related

Dynamic mapping in Salesforce - generate JSON request for call third-party API

I want to generate JSON string from Account sObject field which also contains other sObject.
Please help...
In my experience, the best way to go about this without using middleware is to create a custom metadata type for the API mapping. It will store the JSON key, SObject name, and SObject field.
You can use that data to generate a dynamic SOQL query and then create a map (Map) that can be serialized.
The complexity depends on the JSON you need to generate. If you need sub-objects or arrays of objects in the JSON, it can get complicated.

Querying Salesforce Object Column Names w/SOQL

I am using the Salesforce SOQL snap in a SnapLogic integration between our Salesforce instance and an S3 bucket.
I am trying to use a SOQL query in the Salesforce SOQL snap field "SOQL query*" to return the column names of an object. For example, I want to run a SOQL query to return the column names of the "Account" object.
I am doing this because SOQL does not allow "Select *". I have seen code solutions in Apex for this, but I am looking for a way to do it using only a SOQL query.
You want to query metadata? Names of available tables, names of columns you can see in each table, maybe types instead of real Account/Contact/... data, correct?
You might have to bump the version of the API up a bit, current is 47 / 48 so some objects might not be visible in your current one. Also - what API options you have? SOAP, REST? Is "Tooling API" an option? Because it has very nice official FieldDefinition table to pull this.
It's not perfect but this could get you started:
SELECT EntityDefinition.QualifiedApiName, QualifiedApiName, DataType
FROM FieldDefinition
WHERE EntityDefinition.QualifiedApiName IN ('Account', 'Contact', 'myNamespace__myCustomObject__c')
I don't see the table in the REST API reference but it seems to query OK in Workbench so there's hope.
Generally try to Google around about EntityDefinition, FieldDefinition, EntityParticle... For example this is a decent shot at learning which tables are visible to you:
SELECT KeyPrefix, QualifiedApiName, Label, IsQueryable, IsDeprecatedAndHidden, IsCustomSetting
FROM EntityDefinition
WHERE IsCustomizable = true AND IsCustomSetting = false
Or in a pinch you could try to see which fields your user has permission to query. It's bit roundabout way to do it but I have no idea which tables your connector can "see".
Starting from API version 51.0 there's the FIELDS() function available: it lets you query all fields of a given object similar to "SELECT *"
Example:
SELECT FIELDS(ALL) FROM User LIMIT 200
Reference:
https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_select_fields.htm

Mule Salesforce connector in query operation. List of Maps as input

I have a huge list of Ids and Names for Contacts defined in this simple DW script. Let's show just two for simplicity:
[
{id:'169057',Name:'John'},
{id:'169099',Name:'Mark'}
]
I need salesforce connector to execute a single query (not 1000 unitary queries) about this two fields.
I expect the connector to be able to use a List of Maps as input, as it does using update/insert operations. So, I tried with this Connector config:
I am getting as response a ConsumerIterator. If I do a Object to String transformer but I am getting an empty String as response.
I guess must be a way of executing a big query in just one API call... But I am not finding it. Have in mind I need to use two or more WHERE clauses.
Any idea? Thanks!
I think you need to create two separate list for id and Name values from your input and then use those list in the query using IN.
Construct id list to be used in where clause. This can be executed inside for each with batch size 1000.
Retrieve name and id from contact for each batch
select id, name from contact where id in (id list)
Get the desired id's by matching name retrieved in step 2 within mule.

How to capture datasource name when using Azure Search indexer

I have a multi-tenant index in azure search and I want to populate it with several indexers, each uploading data from one specific tenant.
I want the search to be filtered by a field "tenantid". Each database that an indexer uses as a data source has the "tenantid" as it's name, but there is no function or option I found that enables adding a custom field mapping the name of the database to a field in the search results.
The naive solution to the problem is to add a field in each document in the DB containing the field "tenantid", but I would rather take this info from the database name and reduce my object size.
Any ideas? Thanks a lot.
There's currently no such field mapping function available. Please add this suggestion on Azure Search UserVoice.
To workaround, instead of adding the database name to each document, you can just include it by specifying a datasource query as follows:
SELECT c.id, c._ts, 'my_database' AS database FROM collection c WHERE c._ts >= #HighWaterMark

Retrieve all documents but only specific fields from Cloudant database

I want to return all the documents in a Cloudant database but only include some of the fields. I know that you can make a GET request against https://$USERNAME.cloudant.com/$DATABASE/_all_docs, but there doesn't seem to be a way to select only certain fields.
Alternatively , you can POST to /db/_find and include selector and fields in the JSON body. However, is there a universal selector, similar to SELECT * in SQL databases?
You can use {"_id":{"$gt":0}} as your selector to match all the documents, although you should note that it is not going to be performant on large data sets.

Resources