• Owen Gerig
  • NEWBIE
  • 10 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 3
    Replies
CalEvent calEvent = (CalEvent) JSON.deserialize(calEventJson,  Technician_Dispatch_Util.CalEvent.class);
        System.debug('OGDEBUG TDU calEventJson '+calEventJson);
        System.debug('OGDEBUG TDU updateTechnicianCalEvent calEvent.startTime '+ calEvent.startTime + ' calEvent.endTime '+calEvent.endTime);
 
15:13:56.110 (110381617)|USER_DEBUG|[185]|DEBUG|OGDEBUG TDU calEventJson {"id":"a2M40000000RQeLEAW","title":"WO-00018602 New College of Florida","allDay":false,"startTime":"2015-07-27T00:00:00.000","endTime":"2015-07-27T01:00:00.000","ownerId":"00540000002kHeXAAU","description":"Perform PM visit as detailed on supplied spreadsheet. Check service office's documentation for equipment list.  Contact dispatcher at Help Desk with any questions.  For damaged equipment please specify the following:\n\n* Room Name:\n* Manufacturer:\n* Model:\n* Serial No.:\n* Problem: \n\nROOMS TO COVER:\n\nNew College of Florida - Sarasota Fl - Carriage House\n\nNew College of Florida - Sarasota Fl - CHL 214\n\nNew College of Florida - Sarasota Fl - CHL 221"}
15:13:56.110 (110393767)|SYSTEM_METHOD_EXIT|[185]|System.debug(ANY)
15:13:56.110 (110398648)|STATEMENT_EXECUTE|[186]
15:13:56.110 (110405457)|HEAP_ALLOCATE|[186]|Bytes:56
15:13:56.110 (110440565)|SYSTEM_METHOD_ENTRY|[186]|Technician_Dispatch_Util.CalEvent.__sfdc_startTime()
15:13:56.110 (110524168)|VARIABLE_ASSIGNMENT|[-1]|this|{"allDay":false,"description":"Perform PM visit as  (429 more) ...","endTime":"2015-07-27T05:00:00.000Z","id":"a2M40000000RQeLEAW","ownerId":"00540000002kHeXAAU","startTime":"2015-07-27T04:00:00.000Z","title":"WO-00018602 New Coll (14 more) ..."}|0x7f615512
15:13:56.110 (110541459)|SYSTEM_METHOD_EXIT|[186]|Technician_Dispatch_Util.CalEvent.__sfdc_startTime()
15:13:56.110 (110580245)|SYSTEM_METHOD_ENTRY|[186]|String.valueOf(Object)
15:13:56.110 (110604337)|HEAP_ALLOCATE|[186]|Bytes:19
15:13:56.110 (110618624)|SYSTEM_METHOD_EXIT|[186]|String.valueOf(Object)
15:13:56.110 (110625066)|HEAP_ALLOCATE|[186]|Bytes:18
15:13:56.110 (110637197)|SYSTEM_METHOD_ENTRY|[186]|Technician_Dispatch_Util.CalEvent.__sfdc_endTime()
15:13:56.110 (110699785)|VARIABLE_ASSIGNMENT|[-1]|this|{"allDay":false,"description":"Perform PM visit as  (429 more) ...","endTime":"2015-07-27T05:00:00.000Z","id":"a2M40000000RQeLEAW","ownerId":"00540000002kHeXAAU","startTime":"2015-07-27T04:00:00.000Z","title":"WO-00018602 New Coll (14 more) ..."}|0x7f615512
15:13:56.110 (110715668)|SYSTEM_METHOD_EXIT|[186]|Technician_Dispatch_Util.CalEvent.__sfdc_endTime()
15:13:56.110 (110734393)|SYSTEM_METHOD_ENTRY|[186]|String.valueOf(Object)
15:13:56.110 (110745849)|HEAP_ALLOCATE|[186]|Bytes:19
15:13:56.110 (110758709)|SYSTEM_METHOD_EXIT|[186]|String.valueOf(Object)
15:13:56.110 (110774872)|HEAP_ALLOCATE|[186]|Bytes:112
15:13:56.110 (110785310)|SYSTEM_METHOD_ENTRY|[186]|System.debug(ANY)
15:13:56.110 (110791126)|USER_DEBUG|[186]|DEBUG|OGDEBUG TDU updateTechnicianCalEvent calEvent.startTime 2015-07-27 04:00:00 calEvent.endTime 2015-07-27 05:00:00
15:13:56.110 (110796707)|SYSTEM_METHOD_EXIT|[186]|System.debug(ANY)

You can see from the above log output that the json being passed in are correct:
"startTime":"2015-07-27T00:00:00.000"
"endTime":"2015-07-27T01:00:00.000"
However after calling JSON.deserialize time is added onto them (4 hours)
calEvent.startTime 2015-07-27 04:00:00
calEvent.endTime 2015-07-27 05:00:00

Why is this and how can I prevent against this?
 
I have found a few other webpages describing it and in its most basic form (passing a single string) i can get it working.  But I cannot get it working with my complex objects.
calling apex class directly from javascript (http://sfdcsrini.blogspot.com/2014/09/how-to-call-apex-class-method-from.html)
passing via the script tags in the page (http://www.infallibletechie.com/2013/02/how-to-return-value-from-apex-method-to.html)

Snippet of my Page:

    <!--Apex requirements-->
    <script src="/soap/ajax/15.0/connection.js" type="text/javascript"></script>
    <script src="/soap/ajax/15.0/apex.js" type="text/javascript"></script>
    <script src="{!$Resource.Technician_Dispatch_Javascript}"></script>
<apex:sectionHeader title="Dispatch"/>
    <apex:outputPanel id="bodyPanel">
        <apex:form >
           <div>
                <table class="display" id="workOrdersTable">
                    <thead>
                        <tr>
                            <th>Id</th>
                            <th>Title</th>
                            <th>Account</th>
                            <th>Priority</th>
                        </tr>
                    </thead>
                    <tbody id="workOrdersTableBody">
                    </tbody>
                </table>
            </div>
            
    		<script >
   				var workOrders = JSON.parse(sforce.apex.execute("Technician_Dispatch_Util","populateWorkOrders",{}));
            	populateWorkOrders(workOrders);
            </script>
 
function populateWorkOrders(workOrders){
    //{!REQUIRESCRIPT(""/soap/ajax/18.0/connection.js"")} 
	//{!REQUIRESCRIPT(""/soap/ajax/18.0/apex.js"")} 
    //var workOrders = JSON.parse(sforce.apex.execute("Technician_Dispatch_Util","populateWorkOrders",{}));
    
    alert("populateWorkOrders" +workOrders);
    return;  //just trying to get it to work so returning here, skipping the rest of the code

I never see my alert popup though.  I have tried to add the SRC attribute and reference my specific script but that did not change anything
<script src="{!$Resource.Technician_Dispatch_Javascript}">
var workOrders = JSON.parse(sforce.apex.execute("Technician_Dispatch_Util","populateWorkOrders",{}));
            	populateWorkOrders(workOrders);

//the other way is to just call the method and have it call the apex.execute but that did not change the outcome
</script>

I just need to call a method and get the returned list of workOrders
//Class to hold calendar event data
    public list<workOrder > populateWorkOrders(){
        workOrders = new list<workOrder>();
    
        String workOrderNumber = ApexPages.currentPage().getParameters().get('wno');
        String workOrderId = ApexPages.currentPage().getParameters().get('wid');
        
		System.debug('OGDEBUG number '+workOrderNumber);
		System.debug('OGDEBUG id '+workOrderId);
        
        if(workOrderNumber == '' && workOrderId == ''){
            //TODO - OG should implement a popup alert when this happens
            return null;
        }

        
        
        for(SVMXC__Service_Order__c wo: [SELECT name, Account_Name__c, contactName__c, SVMXC__Case__c, SVMXC__Priority__c, SVMXC__Order_Status__c, SVMXC__Order_Type__c, SVMXC__Dispatch_Status__c, 
            SVMXC__City__c, SVMXC__State__c, SVMXC__Component__c, SVMXC__Customer_Down_Status__c, SVMXC__Billing_Type__c FROM SVMXC__Service_Order__c WHERE id = :workOrderId]) {
                workOrder myWO = new workOrder();
                
                myWO.woNumber = wo.name;
                myWO.account = wo.Account_Name__c;
                myWO.contact = wo.ContactName__c;
                myWO.caseName = wo.SVMXC__Case__c;
                myWO.priority = wo.SVMXC__Priority__c;
                myWO.orderStatus = wo.SVMXC__Order_Status__c;
                myWO.orderType = wo.SVMXC__Order_Type__c;
                myWO.dispatchStatus = wo.SVMXC__Dispatch_Status__c;
                myWO.city = wo.SVMXC__City__c;
                myWO.state = wo.SVMXC__State__c;
                myWO.component = wo.SVMXC__Component__c;
                myWO.customerDownStatus = wo.SVMXC__Customer_Down_Status__c;
                myWO.billingType = wo.SVMXC__Billing_Type__c ;
                
                workOrders.add(myWO);
         }
        
        System.debug('OGDEBUG added '+workOrders);
        return workOrders;
    }

 
CalEvent calEvent = (CalEvent) JSON.deserialize(calEventJson,  Technician_Dispatch_Util.CalEvent.class);
        System.debug('OGDEBUG TDU calEventJson '+calEventJson);
        System.debug('OGDEBUG TDU updateTechnicianCalEvent calEvent.startTime '+ calEvent.startTime + ' calEvent.endTime '+calEvent.endTime);
 
15:13:56.110 (110381617)|USER_DEBUG|[185]|DEBUG|OGDEBUG TDU calEventJson {"id":"a2M40000000RQeLEAW","title":"WO-00018602 New College of Florida","allDay":false,"startTime":"2015-07-27T00:00:00.000","endTime":"2015-07-27T01:00:00.000","ownerId":"00540000002kHeXAAU","description":"Perform PM visit as detailed on supplied spreadsheet. Check service office's documentation for equipment list.  Contact dispatcher at Help Desk with any questions.  For damaged equipment please specify the following:\n\n* Room Name:\n* Manufacturer:\n* Model:\n* Serial No.:\n* Problem: \n\nROOMS TO COVER:\n\nNew College of Florida - Sarasota Fl - Carriage House\n\nNew College of Florida - Sarasota Fl - CHL 214\n\nNew College of Florida - Sarasota Fl - CHL 221"}
15:13:56.110 (110393767)|SYSTEM_METHOD_EXIT|[185]|System.debug(ANY)
15:13:56.110 (110398648)|STATEMENT_EXECUTE|[186]
15:13:56.110 (110405457)|HEAP_ALLOCATE|[186]|Bytes:56
15:13:56.110 (110440565)|SYSTEM_METHOD_ENTRY|[186]|Technician_Dispatch_Util.CalEvent.__sfdc_startTime()
15:13:56.110 (110524168)|VARIABLE_ASSIGNMENT|[-1]|this|{"allDay":false,"description":"Perform PM visit as  (429 more) ...","endTime":"2015-07-27T05:00:00.000Z","id":"a2M40000000RQeLEAW","ownerId":"00540000002kHeXAAU","startTime":"2015-07-27T04:00:00.000Z","title":"WO-00018602 New Coll (14 more) ..."}|0x7f615512
15:13:56.110 (110541459)|SYSTEM_METHOD_EXIT|[186]|Technician_Dispatch_Util.CalEvent.__sfdc_startTime()
15:13:56.110 (110580245)|SYSTEM_METHOD_ENTRY|[186]|String.valueOf(Object)
15:13:56.110 (110604337)|HEAP_ALLOCATE|[186]|Bytes:19
15:13:56.110 (110618624)|SYSTEM_METHOD_EXIT|[186]|String.valueOf(Object)
15:13:56.110 (110625066)|HEAP_ALLOCATE|[186]|Bytes:18
15:13:56.110 (110637197)|SYSTEM_METHOD_ENTRY|[186]|Technician_Dispatch_Util.CalEvent.__sfdc_endTime()
15:13:56.110 (110699785)|VARIABLE_ASSIGNMENT|[-1]|this|{"allDay":false,"description":"Perform PM visit as  (429 more) ...","endTime":"2015-07-27T05:00:00.000Z","id":"a2M40000000RQeLEAW","ownerId":"00540000002kHeXAAU","startTime":"2015-07-27T04:00:00.000Z","title":"WO-00018602 New Coll (14 more) ..."}|0x7f615512
15:13:56.110 (110715668)|SYSTEM_METHOD_EXIT|[186]|Technician_Dispatch_Util.CalEvent.__sfdc_endTime()
15:13:56.110 (110734393)|SYSTEM_METHOD_ENTRY|[186]|String.valueOf(Object)
15:13:56.110 (110745849)|HEAP_ALLOCATE|[186]|Bytes:19
15:13:56.110 (110758709)|SYSTEM_METHOD_EXIT|[186]|String.valueOf(Object)
15:13:56.110 (110774872)|HEAP_ALLOCATE|[186]|Bytes:112
15:13:56.110 (110785310)|SYSTEM_METHOD_ENTRY|[186]|System.debug(ANY)
15:13:56.110 (110791126)|USER_DEBUG|[186]|DEBUG|OGDEBUG TDU updateTechnicianCalEvent calEvent.startTime 2015-07-27 04:00:00 calEvent.endTime 2015-07-27 05:00:00
15:13:56.110 (110796707)|SYSTEM_METHOD_EXIT|[186]|System.debug(ANY)

You can see from the above log output that the json being passed in are correct:
"startTime":"2015-07-27T00:00:00.000"
"endTime":"2015-07-27T01:00:00.000"
However after calling JSON.deserialize time is added onto them (4 hours)
calEvent.startTime 2015-07-27 04:00:00
calEvent.endTime 2015-07-27 05:00:00

Why is this and how can I prevent against this?
 
I have found a few other webpages describing it and in its most basic form (passing a single string) i can get it working.  But I cannot get it working with my complex objects.
calling apex class directly from javascript (http://sfdcsrini.blogspot.com/2014/09/how-to-call-apex-class-method-from.html)
passing via the script tags in the page (http://www.infallibletechie.com/2013/02/how-to-return-value-from-apex-method-to.html)

Snippet of my Page:

    <!--Apex requirements-->
    <script src="/soap/ajax/15.0/connection.js" type="text/javascript"></script>
    <script src="/soap/ajax/15.0/apex.js" type="text/javascript"></script>
    <script src="{!$Resource.Technician_Dispatch_Javascript}"></script>
<apex:sectionHeader title="Dispatch"/>
    <apex:outputPanel id="bodyPanel">
        <apex:form >
           <div>
                <table class="display" id="workOrdersTable">
                    <thead>
                        <tr>
                            <th>Id</th>
                            <th>Title</th>
                            <th>Account</th>
                            <th>Priority</th>
                        </tr>
                    </thead>
                    <tbody id="workOrdersTableBody">
                    </tbody>
                </table>
            </div>
            
    		<script >
   				var workOrders = JSON.parse(sforce.apex.execute("Technician_Dispatch_Util","populateWorkOrders",{}));
            	populateWorkOrders(workOrders);
            </script>
 
function populateWorkOrders(workOrders){
    //{!REQUIRESCRIPT(""/soap/ajax/18.0/connection.js"")} 
	//{!REQUIRESCRIPT(""/soap/ajax/18.0/apex.js"")} 
    //var workOrders = JSON.parse(sforce.apex.execute("Technician_Dispatch_Util","populateWorkOrders",{}));
    
    alert("populateWorkOrders" +workOrders);
    return;  //just trying to get it to work so returning here, skipping the rest of the code

I never see my alert popup though.  I have tried to add the SRC attribute and reference my specific script but that did not change anything
<script src="{!$Resource.Technician_Dispatch_Javascript}">
var workOrders = JSON.parse(sforce.apex.execute("Technician_Dispatch_Util","populateWorkOrders",{}));
            	populateWorkOrders(workOrders);

//the other way is to just call the method and have it call the apex.execute but that did not change the outcome
</script>

I just need to call a method and get the returned list of workOrders
//Class to hold calendar event data
    public list<workOrder > populateWorkOrders(){
        workOrders = new list<workOrder>();
    
        String workOrderNumber = ApexPages.currentPage().getParameters().get('wno');
        String workOrderId = ApexPages.currentPage().getParameters().get('wid');
        
		System.debug('OGDEBUG number '+workOrderNumber);
		System.debug('OGDEBUG id '+workOrderId);
        
        if(workOrderNumber == '' && workOrderId == ''){
            //TODO - OG should implement a popup alert when this happens
            return null;
        }

        
        
        for(SVMXC__Service_Order__c wo: [SELECT name, Account_Name__c, contactName__c, SVMXC__Case__c, SVMXC__Priority__c, SVMXC__Order_Status__c, SVMXC__Order_Type__c, SVMXC__Dispatch_Status__c, 
            SVMXC__City__c, SVMXC__State__c, SVMXC__Component__c, SVMXC__Customer_Down_Status__c, SVMXC__Billing_Type__c FROM SVMXC__Service_Order__c WHERE id = :workOrderId]) {
                workOrder myWO = new workOrder();
                
                myWO.woNumber = wo.name;
                myWO.account = wo.Account_Name__c;
                myWO.contact = wo.ContactName__c;
                myWO.caseName = wo.SVMXC__Case__c;
                myWO.priority = wo.SVMXC__Priority__c;
                myWO.orderStatus = wo.SVMXC__Order_Status__c;
                myWO.orderType = wo.SVMXC__Order_Type__c;
                myWO.dispatchStatus = wo.SVMXC__Dispatch_Status__c;
                myWO.city = wo.SVMXC__City__c;
                myWO.state = wo.SVMXC__State__c;
                myWO.component = wo.SVMXC__Component__c;
                myWO.customerDownStatus = wo.SVMXC__Customer_Down_Status__c;
                myWO.billingType = wo.SVMXC__Billing_Type__c ;
                
                workOrders.add(myWO);
         }
        
        System.debug('OGDEBUG added '+workOrders);
        return workOrders;
    }