Salesforce Upsert using External Id gives an INVALID_FIELD Error - java

I have a custom object obj__c with external id extId__c in SFDC. Based on the article in https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/dome_upsert.htm I do a /services/data/v40.0/sobjects/obj__c/extId__c/45754?_HttpMethod=PATCH call on Workbench. It updates the the record, if an obj__c with extId 45754 already exists. But if the obj__c doesn't exist then the following error is thrown (Basically Insertion).
message: The extId__c field should not be specified in the sobject data.
errorCode: INVALID_FIELD

there are some changes post API version 37.0, which suggest using POST for insert instead of PATCH. You may try changing version to v36.0(or anything less than 37) , example: /services/data/v36.0/sobjects/obj__c/extId__c/45754?_HttpMethod=PATCH

I finally figured out the issue. I was passing extId__c field in the payload body also, which is forbidden.

Related

Spring ReactiveCrudRepository doesn't support PUT? TransientDataAccessException

I'm using Spring to build a simple Web app. At the front end I have a REST api, which has a PUT method like this: /api/v1/apple/{id}
When the call comes in to this endpoint, the body is deserialised to an Apple.
In the spec for PUT it says: "The PUT method requests that the enclosed entity be stored under the supplied Request-URI. If the Request-URI refers to an already existing resource, the enclosed entity SHOULD be considered as a modified version of the one residing on the origin server. If the Request-URI does not point to an existing resource, and that URI is capable of being defined as a new resource by the requesting user agent, the origin server can create the resource with that URI."
So if apple 21 exists in the DB (and is therefore reachable at /api/v1/apple/21), it should be replaced with the one in the request.
But if it doesn't, a new one should be created, as per the apple in the request, with primary key 21 and URI /api/v1/apple/21.
The problem is that the ReactiveCrudRepository seems not to support this.
According to the release notes, since spring-data r2dbc 1.0.0, if you call save() and the row doesn't exist in the database, it throws a TransientDataAccessException. I see the following:
Failed to updated table [apples]. Row with Id [21] does not exist.
org.springframework.dao.TransientDataAccessResourceException: Failed to updated table [apples]. Row with Id [21] does not exist.
at app//org.springframework.data.r2dbc.core.R2dbcEntityTemplate.lambda$doUpdate$14(R2dbcEntityTemplate.java:707)
.....
So if I supply an ID for my new Apple, I can't create it - at least not using ReactiveCrudRepository. If I remove the ID from the POJO first, it will create it, but with an assigned ID - in other words calling PUT /api/v1/apple/21 will result in creation of an apple, but with some other id (not 21).
What am I missing here? There appear to be no alternatives to the save() method which behave the way I need.

List of all errorCode in MySQLException in io.vertx.mysqlclient

Is there any source, where I can get list of all errorCode/errorMessage in MySQLException (io.vertx.mysqlclient)
For ex:
1062 is MySQL Duplicate Key
While you asked for vert.x codes, probably source material- MySql Error reference would help https://dev.mysql.com/doc/mysql-errors/8.0/en/ There are server and client side as well as global error codes listed there.
Also, check out https://github.com/sambrmg/mysql-error-codes/blob/master/index.js
In MySQL %s represents a String ID and %d is representing a primary key(usually) decimal.
1062 is about an identical column value as an id column or such like.
https://dev.mysql.com/doc/mysql-errors/8.0/en/client-error-reference.html
Get the PDF download of this page in the left column of all the error codes.
note: If you use PHP it has similar numeric error messages (just to not confuse it).
note: https://dev.mysql.com/doc/mysql-errors/8.0/en/server-error-reference.html
https://dev.mysql.com/doc/mysql-errors/8.0/en/global-error-reference.html for mysql errors.
Also, I had same error code from MariaDB, and found this link useful. https://mariadb.com/kb/en/mariadb-error-codes/#shared-mariadbmysql-error-codes

IncorrectResultSizeDataAccessException when no entity is found. First returned when multiple are found

I'm trying to find the reason for one strange behavior. Lets say I have Spring data repository which contains a few methods. One of them has a signature like this:
public Entity findByEntityKeyAndValidToDateAfterAndCorrectionDateAfter(BigInteger entityKey, Timestamp validToDate, Timestamp correctionDate);
I receive an issue with stacktrace with the following error:
org.springframework.dao.IncorrectResultSizeDataAccessException
I decided to add two records which have to be returned when I execute this query.
After calling this method instead of throwing the exception the query returns only one of the results. This was strange to my that is why I copy the query from the log and execute it on my SQL developer with the same parameters. The query return both results. I try to change the method signature to return list of entities:
public List<Entity> findByEntityKeyAndValidToDateAfterAndCorrectionDateAfter(BigInteger entityKey, Timestamp validToDate, Timestamp correctionDate);
In this case, the query returns two results.
Any idea why this may happen? And why this query does not throw this exception?
Spring data version is 1.10.1.RELEASE
When using a find method returning a singular type, the following semantics should apply:
0 elements found => return null or Optional.empty if applicable.
1 element found => return that element.
more than 1 element found => exception should be thrown.
Since this is not what you seem to see please upgrade to at least the current minor version (1.10.11), but preferably to the current GA release(1.11.7). If the problem still persists please create an issue at https://jira.spring.io/browse/DATAJPA/?selectedTab=com.atlassian.jira.jira-projects-plugin:summary-panel

Can't create proper spring data custom query using reference field as parameter

I'm trying to make custom spring Data query using field from reference as query
parameter. When i performed this query via REST i had no results at all:
I enabled hibernate logs and copy it to H2 console and I got many results:
My Flight and Airport entities are very simple
So what am I doing wrong? I have other simpler methods and they work fine using browser. I tried the same using Query annotation(second method on second screen), but I got same results. (Copied generated sql query to H2 console and received many results but it didn't work via REST).
EDIT
I found the solution. I just removed quotation marks from URL and
it works well :D
Sorry for my inattention.
Regards,
Michal
I found the solution. It was very simple. Basically I just removed quotation marks from URL and it works well :D
Actual method in Repository looks like:
List findFlightsByFromCityAndToCity(#Param("from") String from, #Param("to") String to);
Regards,
Michal

Unboundid not returning requested LDAP attributes. Why?

I have written a program that reads a webservice, retrieving user data, and then is supposed to push that data to ActiveDirectory, thus updating the user's title, address, phone numbers, etc.
The problem is that when I perform the search using the Unboundid Connection class the requested attributes are not returned. Below is the search code:
SearchResult result = connection.search( properties.getProperty("ldap.search.baseDN"),
SearchScope.SUB, "(cn=" + userId + ")",
"personalTitle", "department", "company", "manager", "telephoneNumber",
"streetAddress", "I", "st", "postalCode", "c", "pager", "mobile",
"fax", "cn");
The above code locates the desired user and the cn attribute is returned as expected, but the other attributes all fail to return. If I connect to AD using JXplorer using the same connection credentials, I'm able to see all the desired attributes exist, but are simply not being returned.
I have tried substituting SearchRequest.ALL_OPERATIONAL_ATTRIBUTES, SearchRequest.ALL_USER_ATTRIBUTES and SearchRequest.REQUEST_ATTRS_DEFAULT rather than listing the fields explicitly, but with no success.
I have also looked at the 'Schema' object returned from 'connection.getSchema()' and can see that personalTitle should exist:
connection.getSchema().getAttributeType("personalTitle")
The above code returns:
1.2.840.113556.1.2.615 NAME 'personalTitle' SYNTAX '1.3.6.1.4.1.1466.115.121.1.15' SINGLE-VALUE
So maybe this is a user permission issue? Has anyone experienced this and know how to resolve it?
Thanks,
Mike
LDAP search result entries only include attributes that actually have values, so the behavior you are seeing from the UnboundID LDAP SDK is appropriate and correct. Even if you explicitly request a particular attribute, that attribute will only be included in the entry if it has one or more values.
I think that you're confused by JXplorer because it's reading the schema to determine what attributes could possibly be included in the entry based on its object classes and is showing them to you so that you can set values for those attributes in the editor. But that doesn't mean that the entry returned by the server actually includes any information about those attributes.
To verify this, you can use the ldap-debugger tool provided with the LDAP SDK to see the actual LDAP communication that occurs. Just run a command like:
tools/ldap-debugger --hostname {directory-server-address} \
--port {directory-server-port} --listenPort {listen-port}
This will create a very simple LDAP proxy server that decodes all requests and responses that pass through it. To use it, simply point JXplorer at the specified listen-port. You will see that when JXplorer retrieves the entry, the entry returned by the server will only contain attributes that actually have values.
If you want to figure out what all the possible attributes are that you can include in a given entry, then use the LDAPConnection.getSchema method to retrieve the server schema, then Schema.getObjectClass for each of the object classes in the target entry, and finally use the ObjectClassDefinition.getRequiredAttributes and ObjectClassDefinition.getOptionalAttributes methods to see what attribute types must and may be used in entries with that object class.

Categories