You need to sign in to do that
Don't have an account?

Can I retrieve the password from Named Credentials before send the message?
I'm building an integration with a SOAP API v1.2, so I'm not able to use WSDL2Apex and I must create my own Request, and send it using Http.send(), storing the endpoint, user and password in a Named Credential.
This SOAP API uses the standard PasswordDigest security in the XML header, and as this kind of authentication is not managed automaticaly by Salesforce (I do not understand why, it is an standard used frecuently), I must build the XML security header manually by encrypting the nonce + timestamp + password.
As salesforce merge the fields after the Http.send(), I need to obtain the password previously to encrypt it and build the XML header, so I'm not able to use '{!$Credential.Password}' and SOQL do not allows access to ii either.
So, how can I access the Named Credential password to build the XML security header node?
This SOAP API uses the standard PasswordDigest security in the XML header, and as this kind of authentication is not managed automaticaly by Salesforce (I do not understand why, it is an standard used frecuently), I must build the XML security header manually by encrypting the nonce + timestamp + password.
As salesforce merge the fields after the Http.send(), I need to obtain the password previously to encrypt it and build the XML header, so I'm not able to use '{!$Credential.Password}' and SOQL do not allows access to ii either.
So, how can I access the Named Credential password to build the XML security header node?
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_callouts_named_credentials_custom_headers_bodies.htm
@Lokeswara Reddy, Unfortunatelly Salesforce does not allows to do this. The way Salesforce builded Named Credentials is useless, most of the API's require to maniputlate dinamically the username or the password. So the only option is storing it in a Custom Setting.
Http http = new Http();
HttpRequest request = new HttpRequest();
// This line must be 1st. This is where apex figures out which callout to use.
request.setEndpoint('callout:credential_name');
// After the above line, we can use the values of UserName and Password defined for the callout
// Also make sure both 'Allow Merge Fields in HTTP Header' and 'Allow Merge Fields in HTTP Body' are checked in SETUP->Named //Credentials->credential_name
request.setBody('api_username={!$Credential.UserName}&api_key={!$Credential.Password}');
request.setMethod('GET');
HttpResponse response = http.send(request);
See https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_callouts_named_credentials_merge_fields.htm.
You can get look like this. Its worked.
ref (https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_callouts_named_credentials_merge_fields.htm)