Sunday 19 June 2016

Visualforce - create an event record using a custom button and visualforce page

visual force page to create event record

requires
visualforce page
controller class
button

visualforce page

<apex:page standardController="Event" extensions="macalendarentry" showheader="false" sidebar="false">
<apex:form >
<apex:pageblock title="MArket Appraisal Calendar Entry" mode="edit">
 <apex:pageBlockButtons location="top">
 <apex:commandButton action="{!save}" value="Save"/>


 </apex:pageBlockButtons>


<apex:pageBlockSection title="Calendar Details" columns="4" >


<apex:inputfield value="{!Event.Ownerid}" >
</apex:inputfield>



<apex:inputfield value="{!Event.Subject}" >
</apex:inputfield>

<apex:inputfield value="{!Event.WhatId}" >
</apex:inputfield>

<apex:inputfield value="{!Event.Type}" >
</apex:inputfield>

<apex:inputfield value="{!Event.StartDateTime}" >
</apex:inputfield>

<apex:inputfield value="{!Event.EndDateTime}" >
</apex:inputfield>
<apex:inputfield value="{!Event.Event_Status__c}" >
</apex:inputfield>
<apex:inputfield value="{!Event.Cancellation_Reason__c}" >
</apex:inputfield>
<apex:inputfield value="{!Event.Location}" >
</apex:inputfield>
<apex:inputfield value="{!Event.ShowAs}" >
</apex:inputfield>

</apex:pageBlockSection>


<apex:pageBlockSection title="Other Information" columns="4">
<apex:inputfield value="{!Event.Location}" >
</apex:inputfield>
<apex:inputfield value="{!Event.ShowAs}" >
</apex:inputfield>
</apex:pageBlockSection>

<apex:pageBlockSection title="Description Information" columns="4">
<apex:inputfield value="{!Event.Description}" >
</apex:inputfield>
</apex:pageBlockSection>
</apex:pageblock>


</apex:form>
</apex:page>

controller
(to prepopulate values in edit screen)
public class macalendarentry {
   public event event{get;set;}
    public macalendarentry(ApexPages.StandardController stdController){

        if(event == null) event = new Event();
        event.ownerid = ApexPages.currentPage().getParameters().get('ownerID');
        event.whatid = ApexPages.currentPage().getParameters().get('whatid');
     
    }
}

button
execute javascript/onclick javascript
window.open('/apex/ADD2Calendar?whatid={!Easy_Opportunity__c.Id}&ownerid={!$User.Id}', '_blank', 'toolbar=0,location=0,menubar=0');

No comments:

Post a Comment