0

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.setEndpoint('callout:Tooling_API_User/services/Soap/u/46.0');
request.setMethod('POST');
request.setHeader('SOAPAction', '""');
request.setHeader('Content-Type', 'text/xml');
//how to modify the soapEnV to not use the custom setting username and password
request.setBody(soapEnv);

HttpResponse response = new Http().send(request);
String responseBody = response.getBody();
System.debug('Reponse: '+ responseBody);
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 at 21:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.