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
rentalforcerentalforce 

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

Best Answer chosen by Admin (Salesforce Developers) 
NaishadhNaishadh

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

NaishadhNaishadh

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;
    }
}
 

This was selected as the best answer
rentalforcerentalforce
i was indeed able to insert the event.. the "problem" or perhaps a "feature" is that upon inserting the new record, i expected its id field being populated and seeing it as null made me assume it failed and you know what they say about assumptions.. thanks for the answer.