function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
ClimbatizeClimbatize 

Probleme with Event insertion

Hi,

 

I'm experiencing problems with an invent insertion in the Java api.

 

First I create a new instance of my custom object:



TestPlanScheduleC tps = TestPlanScheduleC.Factory.newInstance();

 

Calendar date = Calendar.getInstance();
date.setTime(getJXDatePicker().getDate());
tps.setDesiredDateC(date);
tps.setTestPlanC(saveResult.getId());
tps.setTestPlanR(TP);

SObject[] tab = { tps };


try
{
sfs.Insert(tab);
if(getJCheckBoxCalendar().isSelected())
{
sfs.addToCalendar(new TreeNodeNID(tps), tps.getTestPlanR().getName(), coverTreeTime(), tps.getDesiredDateC());
}
} catch (RemoteException e2)
{..........




 As you can see, mycustom object is created with a java.util.Calendar, with no problem.

But when I creat my event like this:

 

 

public void addToCalendar(final TreeNodeNID treeNodeNID, final String subject, final double d,
final Calendar startDateTime) throws RemoteException, InvalidSObjectFault, InvalidIdFault,
InvalidFieldFault, UnexpectedErrorFault
{

startDateTime.setTimeZone(null);
Event event = Event.Factory.newInstance();
event.setSubject(subject);
event.setDurationInMinutes((int) d);
event.setStartDateTime(startDateTime);
event.setWhatId(treeNodeNID.getId());

Insert(event);

}

 

 

 

 My Insert function throws an error concerning the same Calendar used in my custom object:

 

 

org.apache.axis2.AxisFault: '2009-08-27+02:00' is not a valid value for the type xsd:dateTime



org.apache.axis2.util.Utils.getInboundFaultFromMessageContext(Utils.java:512)
org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:370)
org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:416)
org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:228)
org.apache.axis2.client.OperationClient.execute(OperationClient.java:163)
diva.salesforce.webservice.SforceServiceStub.create(SforceServiceStub.java:2645)
diva.Salesforce_session.Insert(Salesforce_session.java:491)
diva.Salesforce_session.Insert(Salesforce_session.java:542)
diva.Salesforce_session.addToCalendar(Salesforce_session.java:1320)
visual.TestPlanPanel$2.actionPerformed(TestPlanPanel.java:552)
javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
javax.swing.DefaultButtonModel.setPressed(Unknown Source)
javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
org.jvnet.substance.utils.RolloverButtonListener.mouseReleased(RolloverButtonListener.java:111)
java.awt.Component.processMouseEvent(Unknown Source)
javax.swing.JComponent.processMouseEvent(Unknown Source)
java.awt.Component.processEvent(Unknown Source)
java.awt.Container.processEvent(Unknown Source)
java.awt.Component.dispatchEventImpl(Unknown Source)
java.awt.Container.dispatchEventImpl(Unknown Source)
java.awt.Component.dispatchEvent(Unknown Source)
java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
java.awt.Container.dispatchEventImpl(Unknown Source)
java.awt.Window.dispatchEventImpl(Unknown Source)
java.awt.Component.dispatchEvent(Unknown Source)
java.awt.EventQueue.dispatchEvent(Unknown Source)
java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
java.awt.EventDispatchThread.pumpEvents(Unknown Source)
java.awt.EventDispatchThread.pumpEvents(Unknown Source)
java.awt.EventDispatchThread.run(Unknown Source)


 

Does someone see the problem here?
Best Answer chosen by Admin (Salesforce Developers) 
mpiercempierce
The error that axis is throwing is legitimate -- the string it's complaining about is some sort of malformed date with a time zone, which doesn't even make sense. Try using Joda Time to construct a DateTime instance, then calling toCalendar() to get the Calendar instance you need. Joda Time's APIs are a lot easier to work with.

All Answers

mpiercempierce
The error that axis is throwing is legitimate -- the string it's complaining about is some sort of malformed date with a time zone, which doesn't even make sense. Try using Joda Time to construct a DateTime instance, then calling toCalendar() to get the Calendar instance you need. Joda Time's APIs are a lot easier to work with.
This was selected as the best answer
ClimbatizeClimbatize
Joda helped me, but not its toCalendar method, that causes a NullPointerException :)
I just created a new Calendar instance, like this:


Calendar date = Calendar.getInstance();
date.setTime(getJXDatePicker().getDate());

org.joda.time.DateTime sched = new DateTime(date.get(Calendar.YEAR),date.get(Calendar.MONTH),date.get(Calendar.DAY_OF_MONTH),9,0,0,0);


Calendar startDateTime= Calendar.getInstance();
startDateTime.setTime(sched.toGregorianCalendar().getTime());


No wonder why startDateTime calendar works better than the first one, but it works, thank you for the hint ;)