1

I am executing SOQL queries using SOAP API.It might result in Account or Opportunity or other salesforce data.

I want to use the result i.e SObject to be passed to a another API.

But the target API accepts only Serializable objects

So how can I make SObject as serializable?

Is there a way to generate SObject class itself as a serializable?

3
  • Is your target API a local (non web-service) API? What language are you working in?
    – Keith C
    Commented Jun 17, 2015 at 11:44
  • target API is on web-service. I am working in JAVA Commented Jun 18, 2015 at 6:26
  • OK, in Java there is more than one SOAP framework. If you are using JAXB see How to generate a Java class which implements Serializable interface from xsd using JAXB?; Google for the framework you are using. Or you can manually create serializable classes and transfer the data into those before sending. Or avoid the pain of SOAP altogether and use the JSON/REST Salesforce APIs.
    – Keith C
    Commented Jun 18, 2015 at 7:37

1 Answer 1

0

Apex has a native JSON support. You can use the serializeand deserialize methods to serialize the objects. Here is a example.

Contact con = [SELECT Id, LastName, AccountId FROM Contact LIMIT 1]; 
// Set additional field
con.FirstName = 'Joe'; 
String jsonstring = Json.serialize(con); 
System.debug(jsonstring); 
2

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .