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
anchoviesanchovies 

Can a custom Salesforce webservice return sObjects via SOAP?

Hi all,

I'm trying to create a custom SF webservice and the call it from my .NET app.

So I'm adding my service's WSDL in VS 2012. It does work for a tiny test webservice that returns a string but it doesn't work when I want to return an opportunity.

Can I return sObjects at all?

In case I can, then here are some details:

By not working I mean that I can't reference my web reference in code and when I try to update web reference I'm getting the following error:

VS error

Is there a workaround for this?

 

My tiny test service code is the following (it does work when called from Apex):

global class OpportunitySearch {
    webService static Opportunity[] getOpportunities()
    {
        Opportunity[] searchResults = Database.query('SELECT Name, Id FROM Opportunity  LIMIT 10');
        return searchResults;
    }
}

It behaves the same way when I'm trying to return a single Opportunity or an Account.

 

Thanks in advance

James LoghryJames Loghry
I haven't come across any errors with this before, so I would recheck your import process to see if something is awry with the wsdl perhaps.

However, have you considered using the Partner (or Enterprise) wsdl instead?

If those don't work, then you could always create a global wrapper class to return the Id and other fields of the Opportunity your .NET webservice needs.
anchoviesanchovies

Hi James,

Thanks for your reply.

Yep, I'm used to Enterprise and Partner wsdl and I'm fond of them, but I think that a custom webservice could be a bit faster (in case you need to do something complex and need to make several calls for it) so I'm trying to explore this option at the moment.

 

The same webservice wsdl does work fine when I change the return type like this:

global class OpportunitySearch {
    webService static string getOpportunities()
    {
        return 'hello';
    }
}

James LoghryJames Loghry
Like I said earlier, you could always utilize a wrapper class

Or, you could also serialize the Opportunity list to JSON as well, if it's small enough, and then deserialize it in your .NET application.
Dianna Raquel Perez GüerequeDianna Raquel Perez Güereque
Make a global class in your webservice class where you iterate the list of your query, convert it with your class and return your class (and not an object). A friend just gave me that tip and worked excelent. 

Hope it helps 2 years later.