SalesForce Opportunity Field inset Error - java

I am integrating with salesforce through java there in Opportunity there is a field named CloseDate .
my code for the same is
opportunitySObject.setField("CloseDate", "2010-01-01");
but i get message='Close Date: value not of required type: 2010-01-01'
statusCode='INVALID_TYPE_ON_FIELD_IN_RECORD'
what i see by quering the database is CloseDate in 2010-01-01 format i.e. yyyy-MM-dd.
Please help.

If this is java code, try passing an actual Date value instead of a string. Your SOAP stack (Axis, CXF, etc.) will serialize the date into the proper wire format.
This advice is really for the Enterprise API. If you're using Partner API, it could be a little different.

Related

Apache Solr date field conversion error in java

I have a problem with a solr Date format. In a jar file the following row generates a conversion error:
**cannot cast 'java.util.ArrayList' to 'java.util.Date'**
Date date = (Date) list.get(0).getFieldValue(fieldName);
The line that generates the error is from mycore-oai-2019.11.jar and MCROAISolrSearcher.java class and as you know I cant change it.
The date column in solr is saved in the following format:
"modified":["2018-08-17T06:10:55Z"]
Debbuging the code in that row I see the following Date format :
I cant understand the error! I am trying for hours to figure it out but nothing. Is the Timezone the problem? Is the mapping of the field a problem? Please any advice/help would safe me!
Thank you in advance!
The field in Solr is a multivalued field - the code expects it to be single valued. A multi valued field returns a list (that's the arraylist you're seeing), while a single valued field returns the field directly (which would be the Date field).
Change your schema (remove multiValued="true" or explicitly set multiValued="false") for the field) and re-index.
By default, in schemaless mode, all fields are multivalued, so that's usually why this appears - you haven't explicitly configured your schema (which you should do in production use).

How to insert JSON data to sql server without converting into Java beans

My requirement is like, i have a json file data as below.,
{Key1: value1, key2: value 2,....} with file name example.json
It should be inserted into sql server as,
Take name: example
Data as below,
Id key1 key2
1 value 1 value 2
I'm searching for a solution such that, there won't be any Java layer complexities, like first converting this data into Java beans then inserting into sql using java database drivers...
Implementation should be language and database independent. In future if i change my database server, then it should be a minimal change.
The coupling should be very loose. Like if i introduce a new key in JSON file, that should be minimal change in the solution.
Tia
So, use some library that can do http request to the server. For eg, if you want insert your json data to server in android app , then use simple libraries like Volley , OkHttp etc.
Problem with your question is , we dont know which server you r using and what application you are doing,, and which programming language you wanna use,, So, im assuming is java android,,

Oracle Date Literal [DD-MON-RR HH.MI.SSXFF AM]

I'm trying to use the timestamp format [DD-MON-RR HH.MI.SSXFF AM] to insert my date.
I can't modify the database settings in anyway possible, and I have to insert the date through a JAVA's string format (I can't modify the class that defined it either).
Having said that, I need to literally reconstruct the format string-by-string without tempering the other class/db.
The nls settings for date is DD-MON-RR. 12-JUN-2012 and 12/JUN/2012 worked perfectly fine.
But I find it difficult to recreate the timestamp part of the date.
Listed below is a few format I've tried.
'12-JAN-12' < success
'12/JAN/2012' < success
'12/JAN/2012 10.30.25.000 AM < failed
'12/JAN/2012 10:30:25.000 AM < failed
Did messed up the : or .? Or was the zero(s) aren't enough for miliseconds? Been in this trouble for hours now.
Thanks in advance.
EDIT
After a few reasoning sessions, the seniors gave their permission to alter the model class. Everything's good now. Thanks for the help and suggestions.
Since you must send a string to the DB, you must rely on the implicit conversion of the oracle DB to the DATE type.
Since you can't change the DB settings, the only thing I can suggest is changing the session settings.
So, if you can run commands against the DB, try:
Statement st = conn.createStatement();
st.execute("alter session set NLS_DATE_FORMAT='dd/mm/yyyy hh24:mi:ss'");
(or some other format (it's not recomended to use mon in your format because it might involve NLS_TERRITORY too))

lotus notes search by date with Java api

I'm trying to select records by date from a Lotus Notes database and have run into trouble with correctly formatting the date.
Here's the relevant code:
public void runNotes() {
Session s;
try {
s = NotesFactory.createSession((String)null, (String)null, "mypassword");
Database hkDB =
s.getDatabase("NBHDH001/YNM", "H\\DHH00001.nsf", false);
DocumentCollection docs = hkDB.search("[Date]>[2012/03/20]");
Date is a field in the record, and when I looked up records (with FTSearch), the date came back in the format above: [yyyy/mm/dd].
The parameter of the search is what I need here.
i.e. what should I put instead of "[Date]>[2012/03/20]"
I tried various constructions with Calendar and DateFormat, but it's not coming together...
Any suggestions?
You should get rid of the square brackets on the field name. The search method expects a Notes Formula, like what you'd put into a view selection formula:
"Date > [03/20/2012]"
It might also be required that dates are in mm/dd/yyyy format, though if you are in a non-US locale I'm not 100% sure.
You mentioned that you have been doing full text searches in the database, so it is definitely worth mentioning this... If the database actually has a full text index, then you may want to consider using the NotesDatabase.FTSearch() method instead of NotesDatabase.Search(). The FTSearch method will be considerably faster for a large database.
The syntax for FTSearch is different from the syntax for Search. You could use either "FIELD Date > 03/20/2012" or "[Date] > 03/20/2012".

How to send a Timestamp field to Oracle stored proc. from Java despite the DB config?

I'm making a request from a java webapp to an Oracle' stored procedure which happens to have a Timestamp IN parameter.
The way info travels is something like:
javaWebApp --} webservice client --} ws --} storedProcedure
And I send the Timestamp param as a formatted string from the webservice client to the ws.
In the testing environment, it works sending:
SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MMM-yyyy hh:mm:ss a");
input.setTimestampField(dateFormat.format(new Date()));
As you see, a formatted string is sent. But in the production environment, it raises an exception
ORA-01830: date format picture ends before converting entire input string.
It relates to the format not being the same, possibly due to differences in configuration from one DB to the other. I know the testing environment should be a replica of the production site, but it is not in my hands to set them properly. And I need to send the Timestamp-as-a-formatted-string field despite the way they setup the database. Any ideas? Thanks in advance.
**** EDIT ****: I've found the way to make it work properly despite the particular configuration. It is as simple as setting the call instruction in the web service with the appropiate Oracle instructions. I mean, the calling to the Oracle stored procedure went from
"call PACKAGE.MYPROCEDURE(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"
to
"call PACKAGE.MYPROCEDURE(?,?,?,?,?,?,TO_TIMESTAMP(?, 'DD-MM-YYYY HH24:MI:SS'),?,?,?,?,?,?,?,?,?,?,?)"
while the format I set in the procedure calling matches the format sent by the webapp using the SimpleDateFormat stated in the original question, slightly modified:
SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
Thank you all for the help and the ideas.
The default NLS_DATE_FORMAT generally doesn't include the time and only a two-digit year. It is probably either DD-MM-YY or MM-DD-YY.
If the WS receives a string and the database stored procedure needs a timestamp, then the two of them will need to negotiate the format mask. Either the WS, when it connects to the database, should set an explicit date format, or the database should be able to accept a string and convert it using a hard-coded format.
Unless there is some particular negotiation you have defined in the WS, nothing the JavaWebApp or WebServiceClient will be able to influence the format that the database assumes the WS is using.
All that said, I'd have a look around any other code at your end and see if there's anything doing a similar translation. You may find something else using a specific format.
What does your query look like in the input prepared statement? That error indicates that Oracle doesn't like the date format you have passed in. Your test environment may have a different NLS_DATE_FORMAT set on the database or machine/driver being used.

Categories