SF allowed the usage of Named Credentials with SOAP callouts but the documentation doesn't really go into details of how to pass/access the Username and Password to the stub.inputHttpHeaders_x . I have a webservice that uses basic authentication and I need to pass the details as below.

final String authHttpHeader = 'Basic ' + EncodingUtil.base64Encode( Blob.valueOf( User_Name + ':' + Password ) );
stub.inputHttpHeaders_x.put( 'Authorization', authHttpHeader );
stub.endpoint_x = 'callout:My_Named_Credential'


If some can give an example of how to access the username/password from the named credentials that will be a great help.


I haven't tested this, but when you are creating your Named Credential you have the option to tick "Generate Authorization Header", which should do this for you automatically:

enter image description here

  • I did check that box and wasn't able to get it to work , but i'll try again . Thanks @smukov – HSG Oct 13 '16 at 17:00
  • it doesn't work. I keep getting the error IO Exception: Unable to tunnel through proxy. Proxy returns "HTTP/1.0 404 Not Found" – HSG Oct 14 '16 at 18:29
  • 1
    That was a user error , sorry I had a bad character in the host name . Thanks @smukov – HSG Oct 14 '16 at 18:37

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.