Use Named Credentials with a SOAP WSDL2APEX class

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'

https://releasenotes.docs.salesforce.com/en-us/winter16/release-notes/rn_security_named_credential_web_service_callouts.htm

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

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x