2

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

HttpRequest req = new HttpRequest();
req.setEndpoint('callout:testSite');
req.setMethod('GET');
Http http = new Http();
HTTPResponse res = http.send(req);
System.debug(res.getBody()); 

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.

0

1 Answer 1

5

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>technical.u[email protected]</username> </NamedCredential>

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

0

You must log in to answer this question.

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