I need to get json response and parse the response into the object(Without using http callout).I need to have application(class) which can get response from other callback url and parse that response into objects.


1 Answer 1


I'm not sure I understand your question. By "without calling out" and "can get response from other callback url" do you mean that you want to publish an endpoint that will accept JSON that is posted to it? If so you can create an @RestResource Apex class with a @HttpPost method that can hanle most of the work - including deserialization from a JSON String to Apex objects - for you.

But if you have the JSON string available and are just asking how to parse it, there are lots of tools to help you parse it into Apex objects. In the JSON class:

  • JSON.deserializeStrict(String jsonString, System.Type apexType)
  • JSON.deserialize(String jsonString, System.Type apexType)
  • JSON.deserializeUntyped(String jsonString)
  • JSON.createParser(String jsonString)

Which of these JSON methods you choose depends on how fixed (known up front) the format of the JSON is. I've listed the methods in order of "best for fixed" though to "best for not fixed".


From your comments below it sounds like you want to setup a REST endpoint in Salesforce that your "call centre website" can invoke. (The process will have to include authentication.) A @RestResource Apex class works well for this and would look something like this:

global with sharing class MyRest {

    global static String doPost(...) {
        // Apex code that does something with the posted data

where ... is up to you: zero or more primitive values, simple Apex classes, SObjects, arrays of any of these. The framework automatically deserializes the JSON based on the parameter list.

To provide an example, this JSON:

{"abc": "some message", "def": [1, 2, 3]}

would be automatically deserialized by this code:

global static String doPost(String abc, Integer[] def) {
    // abc will be "some message"
    // def will be the Integer array 1, 2, 3 

You mention "it should be dynamic" but I am not sure what you mean by that.

  • Thanks for your response .I have issue something like this as follows:
    – user7732
    Commented Apr 7, 2014 at 13:26
  • I am integrating salesforce with the call centre website. In that website I need to configure the call back url,then they will hit my url and send response through that url.That means whenever some customer call me or I call the information is send to my call back url.So I have decided to create one controller which can get response and parse that response in the object.But without sending http callout that means it should be dynamic.
    – user7732
    Commented Apr 7, 2014 at 13:32
  • Please help me out with any small example.
    – user7732
    Commented Apr 7, 2014 at 13:33
  • @user7732 I've added a "PS" section. Hope that helps.
    – Keith C
    Commented Apr 8, 2014 at 21:39

You must log in to answer this question.

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