Skip to main content
replaced http://salesforce.stackexchange.com/ with https://salesforce.stackexchange.com/
Source Link

This is similar to this questionthis question, but I'm wondering about the object I'm sending into the Queueable Class.

Here's the Queuable Class (not much more than debug statements at this point)

public class CalloutLogger implements Queueable{
  public transient HttpRequest req;

  public CalloutLogger(httpRequest request){
    system.debug('Queueable Class Constructor invoked....');
    system.debug('Constructor Input "request": ' + request.toString());
    req = request;
    system.debug('Instance Var "req": ' + req.toString());
  }
  public void execute(QueueableContext context){
    system.debug('CalloutLogger.execute invoked...');
    system.debug('httpRequest.toString() : ' + req.toString());
  } 
}

Here's a demo Class that enqueues the job

public class DemoCallout {
    public void simulatedCallout(){
    //setup HttpRequest
    HttpRequest req = new HttpRequest();
    req.setEndpoint('http://www.notarealendpoint.com/service');
    req.setMethod('GET');
    //Examine operations....
    system.debug('HttpRequest.toString() : ' + req.toString());
    CalloutLogger logger = new CalloutLogger(req);
    system.debug('logger var: ' + logger.req);
    ID jobID = System.enqueueJob(logger);
    system.debug('Enqueued Job with Id: ' + jobID);
  }
}

And here's a bit of anonymous Apex that kicks it all off..

DemoCallout demo = new DemoCallout();
demo.simulatedCallout();

The anonymous Apex is successful with a debug log like this... enter image description here

But the debug log for the Queuable Class give a null reference error for the HttpRequest object variable "req"...

enter image description here

Any suggestions? Is it even possible to pass an HttpRequest object to a Queuable Class (I'm going to want to pass the HttpResponse in too eventually!)

This is similar to this question, but I'm wondering about the object I'm sending into the Queueable Class.

Here's the Queuable Class (not much more than debug statements at this point)

public class CalloutLogger implements Queueable{
  public transient HttpRequest req;

  public CalloutLogger(httpRequest request){
    system.debug('Queueable Class Constructor invoked....');
    system.debug('Constructor Input "request": ' + request.toString());
    req = request;
    system.debug('Instance Var "req": ' + req.toString());
  }
  public void execute(QueueableContext context){
    system.debug('CalloutLogger.execute invoked...');
    system.debug('httpRequest.toString() : ' + req.toString());
  } 
}

Here's a demo Class that enqueues the job

public class DemoCallout {
    public void simulatedCallout(){
    //setup HttpRequest
    HttpRequest req = new HttpRequest();
    req.setEndpoint('http://www.notarealendpoint.com/service');
    req.setMethod('GET');
    //Examine operations....
    system.debug('HttpRequest.toString() : ' + req.toString());
    CalloutLogger logger = new CalloutLogger(req);
    system.debug('logger var: ' + logger.req);
    ID jobID = System.enqueueJob(logger);
    system.debug('Enqueued Job with Id: ' + jobID);
  }
}

And here's a bit of anonymous Apex that kicks it all off..

DemoCallout demo = new DemoCallout();
demo.simulatedCallout();

The anonymous Apex is successful with a debug log like this... enter image description here

But the debug log for the Queuable Class give a null reference error for the HttpRequest object variable "req"...

enter image description here

Any suggestions? Is it even possible to pass an HttpRequest object to a Queuable Class (I'm going to want to pass the HttpResponse in too eventually!)

This is similar to this question, but I'm wondering about the object I'm sending into the Queueable Class.

Here's the Queuable Class (not much more than debug statements at this point)

public class CalloutLogger implements Queueable{
  public transient HttpRequest req;

  public CalloutLogger(httpRequest request){
    system.debug('Queueable Class Constructor invoked....');
    system.debug('Constructor Input "request": ' + request.toString());
    req = request;
    system.debug('Instance Var "req": ' + req.toString());
  }
  public void execute(QueueableContext context){
    system.debug('CalloutLogger.execute invoked...');
    system.debug('httpRequest.toString() : ' + req.toString());
  } 
}

Here's a demo Class that enqueues the job

public class DemoCallout {
    public void simulatedCallout(){
    //setup HttpRequest
    HttpRequest req = new HttpRequest();
    req.setEndpoint('http://www.notarealendpoint.com/service');
    req.setMethod('GET');
    //Examine operations....
    system.debug('HttpRequest.toString() : ' + req.toString());
    CalloutLogger logger = new CalloutLogger(req);
    system.debug('logger var: ' + logger.req);
    ID jobID = System.enqueueJob(logger);
    system.debug('Enqueued Job with Id: ' + jobID);
  }
}

And here's a bit of anonymous Apex that kicks it all off..

DemoCallout demo = new DemoCallout();
demo.simulatedCallout();

The anonymous Apex is successful with a debug log like this... enter image description here

But the debug log for the Queuable Class give a null reference error for the HttpRequest object variable "req"...

enter image description here

Any suggestions? Is it even possible to pass an HttpRequest object to a Queuable Class (I'm going to want to pass the HttpResponse in too eventually!)

Tweeted twitter.com/StackSalesforce/status/831349665589256192
edited tags
Link
Adrian Larson
  • 151.3k
  • 38
  • 247
  • 431
Source Link
John Thompson
  • 2.1k
  • 1
  • 15
  • 26

I want to pass an HttpRequest object to a Class that implements the Queueable interface

This is similar to this question, but I'm wondering about the object I'm sending into the Queueable Class.

Here's the Queuable Class (not much more than debug statements at this point)

public class CalloutLogger implements Queueable{
  public transient HttpRequest req;

  public CalloutLogger(httpRequest request){
    system.debug('Queueable Class Constructor invoked....');
    system.debug('Constructor Input "request": ' + request.toString());
    req = request;
    system.debug('Instance Var "req": ' + req.toString());
  }
  public void execute(QueueableContext context){
    system.debug('CalloutLogger.execute invoked...');
    system.debug('httpRequest.toString() : ' + req.toString());
  } 
}

Here's a demo Class that enqueues the job

public class DemoCallout {
    public void simulatedCallout(){
    //setup HttpRequest
    HttpRequest req = new HttpRequest();
    req.setEndpoint('http://www.notarealendpoint.com/service');
    req.setMethod('GET');
    //Examine operations....
    system.debug('HttpRequest.toString() : ' + req.toString());
    CalloutLogger logger = new CalloutLogger(req);
    system.debug('logger var: ' + logger.req);
    ID jobID = System.enqueueJob(logger);
    system.debug('Enqueued Job with Id: ' + jobID);
  }
}

And here's a bit of anonymous Apex that kicks it all off..

DemoCallout demo = new DemoCallout();
demo.simulatedCallout();

The anonymous Apex is successful with a debug log like this... enter image description here

But the debug log for the Queuable Class give a null reference error for the HttpRequest object variable "req"...

enter image description here

Any suggestions? Is it even possible to pass an HttpRequest object to a Queuable Class (I'm going to want to pass the HttpResponse in too eventually!)