Loading

Content-Length Header Causes an Error in Non-Legacy Named Credential Callouts Starting in Summer '26

Publish Date: May 22, 2026
Description

Customers may encounter the following error when making a Named Credential callout that explicitly sets the "Content-Length" header in Apex:

  1. System.CalloutException: Content-Length header already present

This error occurs when the Apex code includes a line such as:

  1. req.setHeader('Content-Length', '0');

Background

  • Spring '26: A new HTTP component was enabled for Named Credential callouts. Only Named Credentials created after the Spring '26 upgrade used this component, and it enforced stricter handling of the "Content-Length" header.
  • Summer '26: The new component was applied to all non-legacy Named Credentials. As a result, Named Credentials created before Spring '26 are now also subject to this stricter header handling. This behavior change is expected and intentional.

 

Root Cause

The new HTTP component automatically manages the "Content-Length" header. When Apex code also sets this header explicitly, the component detects a conflict and throws an exception, as having duplicate or conflicting "Content-Length" values violates the HTTP specification.

Resolution
  • Remove the explicit "Content-Length" header from the Apex callout code. The new component will manage the header automatically.

     

    For example, remove or comment out the following line:

    1. req.setHeader('Content-Length', '0');

    After this change, the callout should succeed without error.

       
     
    Knowledge Article Number

    005384660

     
    Loading
    Salesforce Help | Article