You need to sign in to do that
Don't have an account?
newbie can't create new event please help
hi - i am trying to create a new event as follows. the problem i am having is that it is successful according to save result array however no event is created. since there is no error reported, i have no clue what is wrong. any pointer is appreciated. thanks.
Calendar now = Calendar.getInstance();
Event e = new Event();
e.setActivityDateTime(now);
e.setSubject("Call");
e.setIsAllDayEvent(false);
e.setDurationInMinutes(new Integer(5));
e.setWhoId(c.getId()); // here i have verified that i have a valid contact "c"
SaveResult[] sr = binding.create(new Event[]{ e }); // here sr.success = true and errors = null
Hi, It should work. I tried your code and it's working fine for me.
Here is the code.
import java.rmi.RemoteException;
import java.util.Calendar;
import javax.xml.rpc.ServiceException;
import com.sforce.soap.enterprise.QueryOptions;
import com.sforce.soap.enterprise.SaveResult;
import com.sforce.soap.enterprise.SforceServiceLocator;
import com.sforce.soap.enterprise.SoapBindingStub;
import com.sforce.soap.enterprise.fault.InvalidFieldFault;
import com.sforce.soap.enterprise.fault.InvalidIdFault;
import com.sforce.soap.enterprise.fault.InvalidSObjectFault;
import com.sforce.soap.enterprise.fault.UnexpectedErrorFault;
import com.sforce.soap.enterprise.sobject.Event;
import com.sungard.constant.IPropertyNames;
import com.sungard.utility.PropertiesUtility;
import com.sungard.utility.SFDCBase;
public class Testing {
private SFDCBase base;
private static QueryOptions qo;
private static SoapBindingStub binding;
public static void main(String[] args) {
Testing t = new Testing();
t.init();
}
public void init() {
try {
//login code
base = SFDCBase.getInstance();
base.login("username","password");
//end login.
Calendar now = Calendar.getInstance();
Event e = new Event();
e.setActivityDateTime(now);
e.setSubject("Call");
e.setIsAllDayEvent(false);
e.setDurationInMinutes(new Integer(5));
e.setWhoId("xxxxxxxxxxxxxxx"); // here i have verified that i have a valid contact "c"
SaveResult[] sr = getBindingStub().create(new Event[] { e });
System.out.println(sr[0].toString());
System.out.println(sr[0].getId());
System.out.println(sr[0].isSuccess());
} catch (InvalidSObjectFault e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (InvalidFieldFault e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (UnexpectedErrorFault e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (InvalidIdFault e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (RemoteException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (ServiceException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
*
* @return
*/
private QueryOptions getQueryOptions() {
if (qo == null) {
qo = new QueryOptions();
qo.setBatchSize(200);
}
return qo;
}
/**
*
* @return
*/
private SoapBindingStub getBindingStub() {
if (binding == null) {
binding = base.getBindingStub();
binding.setHeader(new SforceServiceLocator().getServiceName()
.getNamespaceURI(), "QueryOptions",
getQueryOptions());
}
return binding;
}
}
All Answers
Hi, It should work. I tried your code and it's working fine for me.
Here is the code.
import java.rmi.RemoteException;
import java.util.Calendar;
import javax.xml.rpc.ServiceException;
import com.sforce.soap.enterprise.QueryOptions;
import com.sforce.soap.enterprise.SaveResult;
import com.sforce.soap.enterprise.SforceServiceLocator;
import com.sforce.soap.enterprise.SoapBindingStub;
import com.sforce.soap.enterprise.fault.InvalidFieldFault;
import com.sforce.soap.enterprise.fault.InvalidIdFault;
import com.sforce.soap.enterprise.fault.InvalidSObjectFault;
import com.sforce.soap.enterprise.fault.UnexpectedErrorFault;
import com.sforce.soap.enterprise.sobject.Event;
import com.sungard.constant.IPropertyNames;
import com.sungard.utility.PropertiesUtility;
import com.sungard.utility.SFDCBase;
public class Testing {
private SFDCBase base;
private static QueryOptions qo;
private static SoapBindingStub binding;
public static void main(String[] args) {
Testing t = new Testing();
t.init();
}
public void init() {
try {
//login code
base = SFDCBase.getInstance();
base.login("username","password");
//end login.
Calendar now = Calendar.getInstance();
Event e = new Event();
e.setActivityDateTime(now);
e.setSubject("Call");
e.setIsAllDayEvent(false);
e.setDurationInMinutes(new Integer(5));
e.setWhoId("xxxxxxxxxxxxxxx"); // here i have verified that i have a valid contact "c"
SaveResult[] sr = getBindingStub().create(new Event[] { e });
System.out.println(sr[0].toString());
System.out.println(sr[0].getId());
System.out.println(sr[0].isSuccess());
} catch (InvalidSObjectFault e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (InvalidFieldFault e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (UnexpectedErrorFault e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (InvalidIdFault e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (RemoteException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (ServiceException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
*
* @return
*/
private QueryOptions getQueryOptions() {
if (qo == null) {
qo = new QueryOptions();
qo.setBatchSize(200);
}
return qo;
}
/**
*
* @return
*/
private SoapBindingStub getBindingStub() {
if (binding == null) {
binding = base.getBindingStub();
binding.setHeader(new SforceServiceLocator().getServiceName()
.getNamespaceURI(), "QueryOptions",
getQueryOptions());
}
return binding;
}
}