You need to sign in to do that
Don't have an account?
Gareth 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:
I even tried to access it using this piece of AJAX
Code:
But I only get the alert that says "Failed: undefined".
Any pointers?
Cheers
Gareth.
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.
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
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.
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,
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.
Thanks,