+ Start a Discussion

Javascript remote exception on date field

I'm having trouble with the following code, for date fields only.  I assume it is because the date is not formatted correctly when passing the sobject json to the remote action.  I have tried a few different formats and there seems be a concensus that the date-time format is  ISO8601.  This is fine, but the middle option is formatted with ISO8601 and no dice.  


I am using the javascript date() to format the strings as well.


This does work for normal string/picklist fields, so that is why I am seeking help for the date field values.  Any help is greatly appreciated.



global static void setField(sObject obj) 
	upsert obj;




var sObj = {id: "003Xxxxxxxxxxxxx", Date_of_Next_Meeting__c: "2013-08-26"};
var sObj = {id: "003Xxxxxxxxxxxxx", Date_of_Next_Meeting__c: "2014-06-23T07:00:00.000Z"};
var sObj = {id: "003Xxxxxxxxxxxxx", Date_of_Next_Meeting__c: "6/23/2014"}



js function;

Controller.setField(sObj, function(result, event){
		if (!event.status && event.type == "exception") {

			$j("[id$=':msgs']").text("Unable to save meeting preference:" + event.message).show();



 JSON received in chrome js console:
action: "Controller"
data: Array[1]
message: "Unexpected type for Controller.setField(SObject)"
method: "setField"
ref: false
result: null
statusCode: 400
tid: 15
type: "exception"
vfDbg: true
vfTx: true
where: ""
__proto__: h
$VFRM.Util.error VFRemote.js:114
(anonymous function) VFRemote.js:130
a.Event.fire VFRemote.js:50
a.Observable.fireEvent VFRemote.js:45
VFExt3.Direct.VFExt3.extend.onProviderData VFRemote.js:84
a.Event.fire VFRemote.js:50
a.Observable.fireEvent VFRemote.js:45
VFExt3.direct.RemotingProvider.VFExt3.extend.onData VFRemote.js:92
VFExt3.extend.handleResponse VFRemote.js:73
a VFRemote.js:37
(anonymous function)



It looks like remoting is unable to infer the sobject type based on id.  Try using "sobjecttype".  See docs.


"Your method can take Apex primitives, collections, typed and generic sObjects, and user-defined Apex classes and interfaces as arguments. Generic sObjects must have an ID or sobjectType value to identify actual type. Interface parameters must have an apexType to identify actual type."

Hey cwall, thanks for the reply.

The docs say "sobjects must have an ID OR sobjectType".

I also tried putting sobjectType into the json and it does not resolve the issue.

Any ideas on the formatting of the date sring?

I solved the issue.  I needed to use the javascript data.parse() function.  Works like a charm now.


var ndate = Date.parse("August 23, 2014");
elData = {id:"003XXxxxxxxxxxx", Date_of_Next_Outreach__c : ndate }


Brad BumbaloughBrad Bumbalough
Thanks Troy! that solved my issue too.