Friday, July 27, 2012

NEW EVENT:

NEW EVENT:
This article about How to create a visualforce page for event using custom controller.

public class EventController {
public string valcid{get; set;}
    public EventController(ApexPages.StandardController controller) {
        EventCheck();
    }
public Account Acc{get; set;}
public Event event{get; set;}
public Contact con{get; set;}

    public void EventCheck()
    {
    event=new Event();
    Acc=new Account();
    Contact cont=new Contact();
     String selectedAccId = System.currentPageReference().getParameters().get('what_id');
     if(selectedAccId !=null)
     {
    // System.debug('@@@@@@@@@@@@'+selectedAccId );
     Acc=[Select id,Name from Account where id=:selectedAccId];
     event.whatid='00190000006MsiI';
 //   event.ownerid=UserInfo.getUserId();
 event.ownerid='00590000000lvzt';
   // event.Location=Acc.Name;
    event.StartDateTime=System.Now().addHours(1);
    event.EndDateTime=System.Now().addHours(2); 
  }
   String selectedConId = System.currentPageReference().getParameters().get('who_id');
   if(selectedConId !=null)
   {
    // System.debug('@@@@@@@@@@@@'+selectedAccId );
     
    Cont=[Select id from Contact where id=:selectedConId ];
    event.ownerid=UserInfo.getUserId();
    event.StartDateTime=System.Now().addHours(1);
    event.EndDateTime=System.Now().addHours(2); 
   }
  
    }
Public void GetVal()
{
//System.debug('@@@@@@@@@@@@Entered GetVal**************');
con=[Select LastName,MailingStreet from contact where id=:valcid];
event.description=con.LastName ;
event.location=con.MailingStreet;
}
public Pagereference saveEvent()
{
insert event;
String returnurl='/'+event.whatid;
Pagereference seekerpage=new PageReference(returnurl);  
return seekerpage; 
}
 public Pagereference cancelEvent()
{

String cancelurl='/'+event.whatid;
Pagereference backpage=new PageReference(cancelurl);  
return backpage; 
}  
}

and the VFP looks like this
<apex:page standardController="Event" tabStyle="Event" label="New Event" extensions="EventController">
  <apex:form id="myform" >
  <script>
  function call(nm,n)
  {
  document.getElementById('j_id0:myform:EventPage:Contctid').value=document.getElementById('j_id0:myform:EventPage:Calender:contact_txt_lkid').value;
 }
  function GetVal()
  {
  
  }
  </script>
  <apex:pageBlock id="EventPage" tabStyle="Event">
  <apex:inputHidden id="Contctid" value="{!valcid}"/>
  <apex:actionFunction action="{!GetVal}" name="GetVal" reRender="Description,loc_txt"></apex:actionFunction> 
   <apex:pageBlockButtons title="Event Edit" dir="Event Edit" >
  <apex:commandButton id="SaveEvent" value="Save" Action="{!saveEvent}"/>
  <apex:commandButton id="CancelEvent" value="Cancel" Action="{!cancelEvent}"/>
  </apex:pageBlockButtons>
 <apex:pageBlockSection id="Calender" title="Calendar Details" collapsible="false"  showHeader="true" columns="2"  >
   <apex:inputfield id="assignto_txt" value="{!event.ownerid}" />
   <apex:inputfield id="loc_txt" value="{!event.location}"/>
   <apex:inputfield id="subject_txt" required="true" value="{!event.Subject}"/> 
   <apex:inputfield id="start_txt" value="{!event.StartDateTime}"/>
  <apex:inputfield id="contact_txt" value="{!event.whoid}" onblur="call('{!$Component.myform.EventPage.Calender.contact_txt}','{!$Component.myform.EventPage.Calender.contact_txt_lkid}');GetVal();"/>
  <apex:inputfield id="end_txt" value="{!event.EndDateTime}"/>
   <apex:inputfield id="whoto_txt" value="{!event.whatid}" />
   <apex:inputfield id="allday_txt" value="{!event.IsAllDayEvent}"/>
  </apex:pageBlockSection>
  <apex:pageBlockSection id="Description" title="Description Information" collapsible="false"  showHeader="true" columns="1"  >
   <apex:inputfield id="description_txt" value="{!event.description}" />
    </apex:pageBlockSection>
    <apex:pageBlockSection id="Recurrence" title="Recurrence" collapsible="false"  showHeader="true" columns="1">
    
   
   <div>
   <apex:inputfield id="IsRecurrence"  value="{!event.IsRecurrence}" onclick="ActivityFunction.selectMakeRecurring('IsRecurrence','evt15','evt4','StartDateTime','EndDateTime');" />


 <apex:inputfield id="RecurrenceType" value="{!event.RecurrenceType}"/>&nbsp;&nbsp;<apex:inputfield id="RecurrenceDayOfMonth" value="{!event.RecurrenceDayOfMonth}"/>
   
   <div id="recpat" style="">
<table width="100%">
<tbody>
<tr>
<td class="labelCol">
<label>Frequency</label>
</td>
<td>
<table class="recurrenceTable">
<tbody>
<tr>
<td>
<div>
<div>
<input checked="checked" id="rectypeftd" name="rectype" onclick="ActivityFunction.adjustRecurrenceFrequency('d');" type="radio" value="ftd"/>
<label for="rectypeftd">Daily</label></div>
<div>
<input id="rectypeftw" name="rectype" onclick="ActivityFunction.adjustRecurrenceFrequency('w');ActivityFunction.setDayOfWeekDefault('RecurrenceStartDateTime');" type="radio" value="ftw"/>
<label for="rectypeftw">Weekly</label></div>
<div>
<input id="rectypeftm" name="rectype" onclick="ActivityFunction.adjustRecurrenceFrequency('m');" type="radio" value="ftm"/>
<label for="rectypeftm">Monthly</label></div>
<div>
<input id="rectypefty" name="rectype" onclick="ActivityFunction.adjustRecurrenceFrequency('y');" type="radio" value="fty"/>
<label for="rectypefty">Yearly</label></div></div>
</td>
<td>
<div class="periodElementGroup" id="d" style="display:">
<div><input checked="checked" id="recdd0" name="recd" title="Recurs every weekday" type="radio" value="d0"/>
<label for="recdd0">Every weekday</label></div>
<div>
<input id="recdd1" name="recd" title="Specify interval in days" type="radio" value="d1" /><label for="recdd1">
</label>Every 
<input id="di" name="di" onkeypress="document.getElementById('recdd1').checked=true;" size="3" title="specify interval in days" type="text" value="1"/> day(s)
</div>
</div>
<div class="periodElementGroup" id="w" style="display:none">
<div>Recurs every <input id="wi" name="wi" size="3" title="specify interval in weeks" type="text" value="1"/> week(s) on</div>
<div><input id="1" name="1" type="checkbox" value="1"/><label for="1">Sunday</label>
<input id="2" name="2" type="checkbox" value="1"/>
<label for="2">Monday</label><input id="4" name="4" type="checkbox" value="1"/><label for="4">Tuesday</label><input id="8" name="8" type="checkbox" value="1"/><label for="8">Wednesday</label><input id="16" name="16" type="checkbox" value="1"/><label for="16">Thursday</label><input id="32" name="32" type="checkbox" value="1"/><label for="32">Friday</label><input id="64" name="64" type="checkbox" value="1"/><label for="64">Saturday</label></div></div><div class="periodElementGroup" id="m" style="display:none"><div><input checked="checked" id="recmm0" name="recm" title="Specify number of days into month and monthly interval" type="radio" value="m0"/><label for="recmm0"></label>On day <select id="mdom" name="mdom" onchange="document.getElementById('recmm0').checked=true;" title="select day of the month"><option value="1" selected="selected">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
<option value="31">31</option>
</select> of every <input id="mint" name="mint" onkeypress="document.getElementById('recmm0').checked=true;" size="3" title="specify interval in months" type="text" value="1"/> month(s)</div>
<div><input id="recmm1" name="recm" title="Specify which day of which week and the monthly interval" type="radio" value="m1"/>
<label for="recmm1"></label>On the 
<select id="mnins" name="mnins" onchange="document.getElementById('recmm1').checked=true;" title="select which week of the month">
<option value="1" selected="selected">1st</option>
<option value="2">2nd</option>
<option value="3">3rd</option>
<option value="4">4th</option>
<option value="5">last</option>
</select> 
<select id="mndow" name="mndow" onchange="document.getElementById('recmm1').checked=true;" title="select which day of the week">
<option value="127" selected="selected">day</option>
<option value="1">Sunday</option>
<option value="2">Monday</option>
<option value="4">Tuesday</option>
<option value="8">Wednesday</option>
<option value="16">Thursday</option>
<option value="32">Friday</option>
<option value="64">Saturday</option>
</select> of every 
<input id="mnint" name="mnint" onkeypress="document.getElementById('recmm1').checked=true;" size="3" title="specify interval in months" type="text" value="1"/> 
month(s)</div></div>
<div id="y" style="display:none">
<div>
<input checked="checked" id="recyy0" name="recy" title="Specify month and day" type="radio" value="y0"/>
<label for="recyy0"></label>On every 
<select id="ymoy" name="ymoy" onchange="document.getElementById('recyy0').checked=true;" title="select the month">
<option value="0" selected="selected">January</option>
<option value="1">February</option>
<option value="2">March</option>
<option value="3">April</option>
<option value="4">May</option>
<option value="5">June</option>
<option value="6">July</option>
<option value="7">August</option>
<option value="8">September</option>
<option value="9">October</option>
<option value="10">November</option>
<option value="11">December</option>
</select> 
<select id="ydom" name="ydom" onchange="document.getElementById('recyy0').checked=true;" title="select day of the month">
<option value="1" selected="selected">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
<option value="31">31</option>
</select></div><div><input id="recyy1" name="recy" title="Specify day of particular week in a specific month" type="radio" value="y1"/>
<label for="recyy1"></label>On the 
<select id="ynins" name="ynins" onchange="document.getElementById('recyy1').checked=true;" title="select which week of the month">
<option value="1" selected="selected">1st</option>
<option value="2">2nd</option>
<option value="3">3rd</option>
<option value="4">4th</option>
<option value="5">last</option>
</select> <select id="yndow" name="yndow" onchange="document.getElementById('recyy1').checked=true;" title="select which day of the week">
<option value="127" selected="selected">day</option>
<option value="1">Sunday</option>
<option value="2">Monday</option>
<option value="4">Tuesday</option>
<option value="8">Wednesday</option>
<option value="16">Thursday</option>
<option value="32">Friday</option>
<option value="64">Saturday</option>
</select> of <select id="ynmoy" name="ynmoy" onchange="document.getElementById('recyy1').checked=true;" title="select the month"><option value="0" selected="selected">January</option>
<option value="1">February</option>
<option value="2">March</option>
<option value="3">April</option>
<option value="4">May</option>
<option value="5">June</option>
<option value="6">July</option>
<option value="7">August</option>
<option value="8">September</option>
<option value="9">October</option>
<option value="10">November</option>
<option value="11">December</option>
</select></div></div></td></tr>
</tbody></table></td></tr>

</tbody></table></div>
   
   
   
    <apex:inputfield id="RecurrenceStartDateTime" value="{!event.RecurrenceStartDateTime}" required="true"/>
     <apex:inputfield id="RecurrenceEndDateOnly" value="{!event.RecurrenceEndDateOnly}" required="true"/>
  
   </div>
    </apex:pageBlockSection>
  </apex:pageBlock>
  </apex:form>
  <!--call('{!$Component.myform.EventPage.Calender.contact_txt}','{!event.whoid}');-->
</apex:page>


1 comment:

  1. Hi Rajendra,

    This is a good blog.I am also creating new event using VFP.This blog good reference for me. But i have doubt on Attachment and Invite others related list in Event Creation.How to Create those related lists.

    Thanks,
    DevineniSarath

    ReplyDelete