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
Max PowerMax Power 

How do I access an object returned from an Apex web service method?

I'm using the AJAX toolkit to call an Apex web service method that returns an object.  I know the web service method works because I can test it using the System Log Console.  I wasn't really sure how this would work, so I added a call to 'debugger;' in my javascript function that calls sforce.apex.execute, so that I could examine what gets returned from the web service method.  But I just get an empty object back.
 
Can anyone help me out with this?  I'm at a loss as to what I can try, or why this isn't working.
 
Thanks in advance,
Max
sfdcfoxsfdcfox
The result is an array of return values. If you expect only one value, use element [0] of the array to find the resultant value. You can use the JavaScript convention of using parseInt(), etc, to convert the value to a native JavaScript value (they default to strings, it appears...). Complex objects return a named array (or hash, if you prefer) that contains the names of the fields and their values.
Max PowerMax Power
Thanks, but my problem was that the object being returned from the the sforce.ajax.execute was empty.  There was nothing in element[0].
 
I ended up stumbling across the answer.  It turns out that my problem was that the custom object returned from my Apex webservice did not have any member variables declared using the webservice keyword.  Once I added this keyword, all of the attribues were accessible in the object returned from the sforce.ajax.execute method.
 
Hopefully this will help someone else in the future.
 
-Max