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 

Visualforce page won't create a new record

I'm trying to create a visualforce page on the contact that will first insert a related event and then open up a web page. For some reason, I can populate the field values of the record but when I try to insert the record it breaks my code.

Here is my code:
<apex:page id="pg" standardController="Contact">
    <script>
		function openPage (){
            var ev = new sforce.SObject("Event");
            ev.Subject = "Join.me Meeting w/ " + "{! Contact.FirstName}" + " " + "{! Contact.LastName}";
            ev.ActivityDate = "{! NOW()}";
            ev.DurationInMinutes = 30;
            ev.WhoId = "{! Contact.Id}";
            ev.JoinmeV2__Join_Me_Activity__c = true;
        	ev.JoinmeV2__Meeting_Code__c = "thewealthpool";
            
            sforce.connection.create([ev]);
            
            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>

 
bhanu_prakashbhanu_prakash
Hi Kyle,
Mark as best answer, If it resloves !!
I have modified code
<apex:page id="pg" standardController="Contact" lightningStylesheets="true">
    <apex:slds/>
    <script>
        function openPage() {
            var ev = new sforce.SObject("Event");
            ev.Subject = "Join.me Meeting w/ " + "{! Contact.FirstName}" + " " + "{! Contact.LastName}";
            ev.ActivityDate = "{! NOW()}";
            ev.DurationInMinutes = 30;
            ev.WhoId = "{! Contact.Id}";
            ev.JoinmeV2__Join_Me_Activity__c = true;
            ev.JoinmeV2__Meeting_Code__c = "thewealthpool";

            sforce.connection.create([ev]);

            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  onClick="openPage()" action="{!save}" value="Save" id="theButton"/> -->
        <apex:pageBlock>
            <apex:pageBlockSection>
                <apex:inputField value="{!Contact.FirstName}" />
                <apex:inputField value="{!Contact.LastName}" />
            </apex:pageBlockSection>
            <apex:pageBlockButtons location="bottom">
                <apex:commandButton action="{!save}" value="Save" />
            </apex:pageBlockButtons>
        </apex:pageBlock>
    </apex:form>
</apex:page>

These code will create contact from vf page 
<apex:pageBlock>
            <apex:pageBlockSection>
                <apex:inputField value="{!Contact.FirstName}" />
                <apex:inputField value="{!Contact.LastName}" />
            </apex:pageBlockSection>
            <apex:pageBlockButtons location="bottom">
                <apex:commandButton action="{!save}" value="Save" />
            </apex:pageBlockButtons>
        </apex:pageBlock>

Please post your error and Iam unable to get popup

Mark as resloved if it helps :) :)
Thanks, 
Bhanu Prakash
visit ForceLearn.com (https://www.forcelearn.com/)   ​