+ Start a Discussion

Help with Custom Button to access Visual force page

Hi ,

I have an Object Order Calendar which is a Lookup to Account . I have a calendar visual force page which contains all the records when i access it through apex/calendar . Order calendar will be a realted list on account and when i click a button from the related list or from account deatil page how do i make sure that records on the page only shows that account and not for all accounts . This is the URL i am using now
<apex:page controller="CalendarExample_Controller" action="{!pageLoad}">

    <link href="{!$Resource.fullCalendarCSS}" rel="stylesheet" />
    <link href="{!$Resource.fullCalendarPrintCSS}" rel="stylesheet" media="print" />
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
    <script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>
    <script src="{!$Resource.fullCalendarMinJS}"></script>
        //We need to wrap everything in a doc.ready function so that the code fires after the DOM is loaded
        $(document).ready(function() {  
            //Call the fullCallendar method. You can replace the '#calendar' with the ID of the dom element where you want the calendar to go.
                header: {
                    left: 'prev,next today',
                    center: 'title',
                    right: 'month'
                     //right: 'month,agendaWeek,agendaDay'
                editable: false,
                    //At run time, this APEX Repeat will reneder the array elements for the events array
                    <apex:repeat value="{!events}" var="e">
                            title: "{!e.title}",
                            start: '{!e.startString}',
                            end: '{!e.endString}',
                            url: '{!e.url}',
                            allDay: {!e.allDay},
                            className: '{!e.className}',
    <!--some styling. Modify this to fit your needs-->
        #cal-options {float:left;}
        #cal-legend { float:right;}
        #cal-legend ul {margin:0;padding:0;list-style:none;}
        #cal-legend ul li {margin:0;padding:5px;float:left;  }
        #cal-legend ul li span {display:block; height:16px; width:16px; margin-right:4px; float:left; border-radius:4px;}
        #calendar {margin-top:1px;}
        #calendar a:hover {color:#fff !important;}
        .fc-event-inner {padding:0px;}
        .event-Order {background:#1797c0;border-color:#56458c;}
        .event-Orders {background:#24f424;border-color:#24f424;}
        .event-Orderss {background:#ff0000;border-color:#ff0000;}
    <apex:includeScript value="{!$Resource.moment_min_js}"  /> 
    <apex:sectionHeader title="Order Calendar"/>
    <apex:outputPanel id="calPanel">
        <apex:form >
            <div id="cal-options">
         <!--      <apex:commandButton value="{!IF(includeMyEvents,'Hide My Events','Show My Events')}" action="{!toggleMyEvents}"/> -->
            <div id="cal-legend">
                     <li><span class="event-Order"></span>Order Calendar</li>   
                <div style="clear:both;"><!--fix floats--></div>
            <div style="clear:both;"><!--fix floats--></div>
            <div id="calendar"></div>
public class CalendarExample_Controller extends CCMTY_BaseController {
    public Boolean includeMyEvents {get;set;}
    public list<calEvent> events {get;set;}
    //The calendar plugin is expecting dates is a certain format. We can use this string to get it formated correctly
    String dtFormat = 'EEE, d MMM yyyy HH:mm:ss u';
    //String dtFormat = 'yyyy-MM-dd HH:mm:ss u';

    public CalendarExample_Controller() {
        //Default showing my events to on
        includeMyEvents = true;
    public PageReference pageLoad() {
        events = new list<calEvent>();
         //Get Order Calendar
        for(Order_Calendar__c Ocald : [select Id, Order_Date__c,Type_of_Event__c,Account__c from Order_Calendar__c 
       // where Account__c =:this.getCurrentUserAccount().Id 
            DateTime startDT = datetime.newInstance(Date.Today().Year(),Ocald.Order_Date__c.Month(), Ocald.Order_Date__c.Day());
            //DateTime endDT = Ocald.Delivery_Date__c;
            If (Ocald.Type_of_Event__c =='Place Order')
            calEvent OrderEvent = new calEvent();
           OrderEvent.startString = startDT.format(dtFormat);
           OrderEvent.title = Ocald.Type_of_Event__c;
           OrderEvent.allDay = true;
           OrderEvent.endString = '';
           OrderEvent.account = Ocald.Account__c;
           OrderEvent.url = '/' + Ocald.Id;
           OrderEvent.className = 'event-Order';
            If (Ocald.Type_of_Event__c =='Delivery')
            calEvent OrderEvents = new calEvent();
           OrderEvents.startString = startDT.format(dtFormat);
           OrderEvents.title = Ocald.Type_of_Event__c;
           OrderEvents.allDay = true;
           OrderEvents.endString = '';
           OrderEvents.url = '/' + Ocald.Id;
           OrderEvents.className = 'event-Orders';
            If (Ocald.Type_of_Event__c =='Holiday')
            calEvent OrderEventss = new calEvent();
           OrderEventss.startString = startDT.format(dtFormat);
           OrderEventss.title = Ocald.Type_of_Event__c;
           OrderEventss.allDay = true;
           OrderEventss.endString = '';
           OrderEventss.url = '/' + Ocald.Id;
           OrderEventss.className = 'event-Orderss';
        return null;
    public PageReference toggleMyEvents() {
            includeMyEvents = false;
            includeMyEvents = true;
        return null;
    //Class to hold calendar event data
    public class calEvent{
        public String title {get;set;}
        public Boolean allDay {get;set;}
        public String startString {get;set;}
        public String endString {get;set;}
        public String url {get;set;}
        public String className {get;set;}
        public String account {get;set;}

User-added image