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
DPacDPac 

Calling APEX code from Scontrol and trying to pass a Date and timestamp

I am trying to pass the date and time stamp to a webservice method in APEX code and the apex method returns a boolean.


My code snippet are as follows:

Apex Code:
================================================
package csaContractBatch{

    webService boolean csaWebServiceBatch(Datetime lastRunDate){
       System.debug('lastRunDate:'+lastRunDate);
       return true;
    }
================================================

Scontrol Code:
===========
<html>
<head>
    <script type="text/javascript" src="/js/functions.js"></script>
    <script src="/soap/ajax/8.0/connection.js"></script>
    <script src="/soap/ajax/8.0/apex.js" type="text/javascript"></script>
    <script language="javascript" src="https://www.salesforce.com/services/lib/ajax/beta3.3/sforceclient.js?browser=true" type="text/javascript"></script>
    <script language="javascript" type="text/javascript">
    function initPage(){
      sforceClient.useCookies = true;
      sforceClient.init("{!API.Session_ID}", "{!API.Partner_Server_URL_80}", true);
      setTimeout("setup()",50);
    }
    function setup(){
       now = new Date();
       var apexCode = sforce.apex.execute("csaContractBatch","csaWebServiceBatch",{lastRunDate:now});
       alert(apexCode);
    }



    </script>
</head>

<body onload="javascript:initPage();">

</body>
</html>
========================================================================

When I click the link that calls this scontrol I get the following error in my browser debugger:
uncaught exception: {faultcode:'soapenv:Server', faultstring:, }

Can you please help.
cheenathcheenath
I am not sure what is going wrong, but try this code.
This will give you more detials:

Code:
<html>
<head>
    <script type="text/javascript" src="/js/functions.js"></script>
    <script src="/soap/ajax/8.0/connection.js"></script>
    <script src="/soap/ajax/8.0/apex.js" type="text/javascript"></script>
    <script language="javascript" type="text/javascript">
    function setup(){
       now = new Date();
       try {
           var apexCode = sforce.apex.execute(
             "csaContractBatch","csaWebServiceBatch",{lastRunDate:now});
           alert(apexCode);
       } catch(error) {
         alert(error);
         throw error;
       }
    }

    </script>
</head>

<body onload="setup()">

</body>
</html>

 

DPacDPac
Got the same error:

But with the string parameter it worked fine.