Attempting to switch from using custom setting to named credential for authentication. I've updated the http request endpoint to use the named credential but how to update the SOAP envelope to not use the Login username and password?

Tooling_Setting__c credentialSetting = [Select Username__c, Password__c, Security_Token__c From Tooling_Setting__c Limit 1];

String soapEnv = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:partner.soap.sforce.com"><soapenv:Body><urn:login><urn:username>'+credentialSetting.Username__c+'</urn:username><urn:password>'+credentialSetting.Password__c+credentialSetting.Security_Token__c+'</urn:password></urn:login></soapenv:Body></soapenv:Envelope>';

HttpRequest request = new HttpRequest();
//modified this endpoint to use the named credential
request.setHeader('SOAPAction', '""');
request.setHeader('Content-Type', 'text/xml');
//how to modify the soapEnV to not use the custom setting username and password

HttpResponse response = new Http().send(request);
String responseBody = response.getBody();
System.debug('Reponse: '+ responseBody);

1 Answer 1


In your named credential, configure the 'Allow Merge Fields in HTTP Body` option then look at this example

...or you can go an easier route and call Tooling API via REST.

  • That Merge Field worked lovely into my soap envelope, thanks.
    – ebar
    Aug 1, 2019 at 21:47

You must log in to answer this question.

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