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
Andrew2XAndrew2X 

Error: SOAPAction HTTP Header Missing

Hi All,

 

One of our customers is getting this error message when a lenghty process is being run. Several batches of accounts are fetched from SFDC and processed. The error occurs after about 400 batches are fetched. The first 400 batches fetch and process without errors, then suddenly in the request for the next batch the error occurs.

 

I've examined v16.0 of connection.js and found a line of code that is setting the SOAPAction header on each AJAX request, which is not surprising since the requests work most of the time. The problem seems to be that the header isn't being set on the request after about 400 requests.

 

Here is the JavaScript code that is being executed:

 

 

    this.fetchFirstBatch = function()
    {
        this.sObjects = [];
        var queryString;

try
{
sforce.connection.batchSize = 200;
sforce.connection.batchSizeSpecified = true;

queryString = "SELECT Id, " +
this.fieldNames.streetField + ", " +
this.fieldNames.cityField + ", " +
this.fieldNames.stateField + ", " +
this.fieldNames.postalCodeField + ", " +
this.fieldNames.countryField +
" FROM " + this.objectName + " WHERE " +
this.fieldNames.statusField + " = null " +
(this.objectName == "Lead" ? "AND IsConverted = false " : "");

this.queryResult = sforce.connection.query(queryString);
this.sObjects = this.queryResult.getArray('records');

this.firstBatchFetched = true;
}
catch(error)
{
alert("Fetch " + this.objectName + " failed with error: " + error);
}
};


    this.fetchNextBatch = function()
    {
        this.sObjects.length = 0;    
    
        try
        {
            this.queryResult = sforce.connection.queryMore(this.queryResult.queryLocator);
            this.sObjects = this.queryResult.getArray('records');
        }
        catch(error)
        {
            alert("Fetch next " + this.objectName + " batch failed with error: " + error);
        }
    };

 

 

This code results in an alert with:

 

Fetch next Account batch failed with error: {faultcode:'soapenv:Client', faultstring:'SOAPAction HTTP Header missing', }

 

How can I set the SOAPAction header explicitly before each call to query or queryMore? I've tried sforce.connection.setRequestHeader but get an error saying that method doesn't exist.

 

The error is occuring in the latest versions of Firefox, IE and Chrome. It's possible that this error started happening only recently because other customers have run this processing with huge number of accounts in the past without any errors.

sfdcfoxsfdcfox

I'm not entirely certain why it would be losing the header, since it certainly shouldn't. But regardless, you're trying to implement what has already been written... Just use what comes in the AJAX Toolkit library:

 

 

this.startQuery = function() {
  // Llama llama...

  var results = sforce.connection.query(queryString)
  var iterator = new sforce.QueryResultIterator(results)
  while(iterator.hasNext()) {
    var record = iterator.next()
    this.sObjects.push(record)
  }
}

 

 

It keeps track of the interals for you and so on without you specifically having to worry about hitting the end, etc. Also, you don't need to specify a batch size unless you're attempting to tweak browser performance. Most likely, the default settings will suffice for your purposes.

 

If you'd like to display some type of progress bar, I'd keep the QueryResultIterator and use a setInterval function so the browser has time to "breathe" between pulses (allowing it to repaint its canvas).

 

At any rate, beyond that, have you tried running it in Chrome with Resource Monitoring enabled? That should allow you to closely track whatever is happening at the point the header is lost...