+ Start a Discussion
Jan KuceraJan Kucera 

Getting data from Named Credentials in Apex

Hi, is there a way of accessing the data stored in Spring 15' Named Credentials from apex? For example the username, password and endpoint link?
Himanshu ParasharHimanshu Parashar
Hi Jan,

If you want to get data from NamedCredential it is available as object. you can do SOQL on that 
SELECT DeveloperName,Endpoint,Id,MasterLabel,PrincipalType FROM NamedCredential

and if you want to use that you can do use following documents to do that


Serafin Motos 19Serafin Motos 19
Sorry, but that query does not allows to obtain username and password. I need to obtain the password to include a security header in my XML body using PasswordDigest, and it must be encripted manualy using Apex, so the usual way using '{!$Credential.Password}' does not work for me, because the field replacement is done when we call the Http.send() method with the request, and I need to introduce in that request's body the XML with the PasswordDigest before.
Anybody knows if it is possible?
Lokeswara ReddyLokeswara Reddy
Hi Serafin Motos 19,
Did you get any solution for this?
Serafin Motos 19Serafin Motos 19
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.