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
Gareth DaviesGareth Davies 

Brain problem - how do I expose an APEX verb via the API?

I know this is simple, so I must be doing something wrong. Please help.

I am taking baby steps with APEX - having now created and run triggers I have progressed to creating a package and want to expose it via the API.

This is the package which saves without Error from Eclipse.

Code:
package GWDWebServiceTest{

 webService Id GWDTest(String lastName, Account a)
 {
   Contact  c = new Contact (LastName = lastName, AccountId = a.Id);
   insert c;
   commit;
   return c.id;
 }
}
I expected that when I generated the WSDL (Enterprise or Partner, I've tried both) I would see a method called GWDTest (or perhaps GWDWebServiceTest.GWDTest) but I don't. I have checked that I don't have two packages with the same name and I don't (So it's not a name space issue).

I even tried to access it using this piece of AJAX

Code:
<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"></script>
    <script language="javascript">
        sforce.debug.trace = true;
        
     function makeaContact()
     {
      alert ("Hi");

      try
      {
       var account = sforce.SObject("Account");
       var id = sforce.apex.execute ("GWDWebServiceTest","GWDTest",{a:"Smith",b:account});
       alert (id);
      }
      catch (ex)
      {
       alert ("Failed : " + ex.message);
      }
     }
    </script>

 But I only get the alert that says "Failed: undefined".

Any pointers?

Cheers
Gareth.

 

paul_nakadapaul_nakada
googling apex wsdl returned the following example
  
  • - Log in to your Enterprise, Unlimited, or Developer Edition Salesforce account. You must log in as an administrator or as a user who has the "Modify All Data" permission.
  • - Click Setup, and then under App Setup, click Integrate.
  • - Click Apex API to display the WSDL download page.
  • - Right-click Partner WSDL to display your browser's save options, and save the partner WSDL to a local directory.  
  • - Run WSDL2JAVA to generate the SalesForce API from the wsdl. (If you don't want to do this then download the Partner Samples from the SalesForce site, and extract the partnerSamples.jar from the zip file.)

it's an entirely separate wsdl and endpoint.

-paul

 -- edited post to drop long uri - Kingsley

Message Edited by Kingsley on 02-26-2007 03:06 PM

Gareth DaviesGareth Davies
Thanks Paul but I don't think that's the problem.

What is described there is the download of the WSDL and then the coversion of the WSDL into Java classes (or whatever the Java thing is, I use C#). The problem I have is that the definition is not contained in the WSDL itself.

And this doesn't explain why I also can't see the verb exposed via the AJAX interface which does not require me to generate the WSDL.


zakzak
You're looking in the wrong wsdl, in the app setup under code there will be a list for your package and a link to the WSDL.
cheenathcheenath
Few things:
1. Since your apex method singature is:

webService Id GWDTest(String lastName, Account a)

the apex call to this should be:

var id = sforce.apex.execute( "GWDWebServiceTest",
"GWDTest", {lastName:"Smith",a:account});

Parameter names should match.

2.change this alert:

  alert ("Failed : " + ex.message);

to:

  alert ("Failed : " + ex);

This should give you better error message.

3. Account is created in a different way, instead of
  var account = sforce.SObject("Account");
use:
  var account = sforce.Xml();


Let me know how these changes go. Also try out this tool. It can
generate a test page (like the .Net test page for web services) for you
apex package.

HTS,





 




Gareth DaviesGareth Davies
Cool!

That's got it. It was a brain problem after all

WSDL - was looking in the wrong place.
APEX/AJAX - was just doing it wrong


Thanks for all your help - and great AJAX workbench. Good job!.

Now onward and upward.

Best
Gareth.
Ron WildRon Wild
I haven't seen any documentation on sforce.Xml() .... what if your parameter were an Apex class, or collection?   How would you define your parameter before passing it to the apex.execute() call?

Thanks,