i am using "Named Credential" in my code as below:

HttpRequest req = new HttpRequest();
Http http = new Http();
HTTPResponse res = http.send(req);

and my code is working fine. but i want to manage "Named Credential" value from my custom visualforce page as i want to create a single setting page for my app. i am looking for APEX sample code to do this functionality.


1 Answer 1


NamedCredential can be read via soql but you can not directly insert it in to this objects.

One workaround for this is use metadata API and Post following request to your org.

<?xml version="1.0" encoding="UTF-8"?> <NamedCredential xmlns="http://soap.sforce.com/2006/04/metadata"> <endpoint>https://prodbox-dev.herokuapp.com/v1</endpoint> <label>prodbox_heroku</label> <principalType>NamedUser</principalType> <protocol>Password</protocol> <password>actual_password</password> <username>[email protected]</username> </NamedCredential>

How to call sf metadata API from apex: Has anyone, ever, successfully invoked the Metadata API from within Apex?


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .