We have the following:

  • Source SFDC Org: making a REST Callout towards SFDC Target Org
  • Target SFDC Org: Custom PUT Webservice being referenced from the Source SFDC Org

Source SFDC Org Future method making a callout towards the Target org Webservice. But we need to generate a specific payload. Thus we need to create a JSONGenerator instance using JSONGenerator gen = new JSON.createGenerator(true); However, upon saving it's giving us the error Invalid type: JSON.createGenerator

Structure of the class looks like this:

public class className {
  public static void doTheCallout() {
   JSONGenerator gen = new JSON.createGenerator(true);

    // creation of the payload

Any idea?

  • 1
    Check if you have any class name with JSON Commented Nov 5, 2016 at 11:14

2 Answers 2


The method is static - its a factory for creating instances - so you need this code that does not include a new:

JSONGenerator gen = JSON.createGenerator(true);

In your code the compiler thinks you are trying to create an instance of a class called createGenerator nested inside a class called JSON.

Note that it is usually easier to create JSON by creating a graph of simple Apex objects or by using maps and then using the JSON.serialize method.


Don't use the new keyword. It should only be used when calling constructors, not for calling methods.


JSONGenerator gen = JSON.createGenerator(true);


JSONGenerator gen = new JSON.createGenerator(true);

You must log in to answer this question.

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