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
Kyle BuzzaKyle Buzza 

Creating Event on Visualforce Button Click

I'm trying to both open a link and create a new event on the click of a custom button on the contact object. I'm able to open the link, but when I uncomment the line,
sforce.connection.create([e]);
it breaks the code and neither inserts the new event nor opens the link. I'm not sure what I'm missing. Any help would be appreciated.

Here is my full code:
<apex:page id="pg" standardController="Contact">
    <script>
		function openPage (){
            var e = new sforce.SObject("Event");
            e.Subject = "Join.me Meeting w/ " + "{! Contact.FirstName}" + " " + "{! Contact.LastName}";
            e.ActivityDate = "{! NOW()}";
            e.DurationInMinutes = 30;
            e.WhoId = "{! Contact.Id}";
            e.JoinmeV2__Join_Me_Activity__c = true;
        	e.JoinmeV2__Meeting_Code__c = "thewealthpool";
            
            //sforce.connection.create([e]);
            
            var win = window.open('https://www.join.me', '_blank');
            win.focus();            
        }

	</script>

    
    <apex:form >
        <apex:includeScript value="/soap/ajax/33.0/connection.js"/>
		<apex:includeScript value="/soap/ajax/33.0/apex.js"/>
        <apex:commandbutton image="{!URLFOR($Resource.JoinMeLogo)}" onClick="openPage()"/>
    </apex:form>
    	
</apex:page>


 
Abdul KhatriAbdul Khatri
please update your code with these lines. ActivityDateTime is mandatory for Event.
e.ActivityDate = new Date();
e.ActivityDateTime = new Date();