1

I am trying to pull the namedcredentials using getNamedCredentials() method in apex but it's not working in anonymous window. This is the error I am getting.

error:

Method does not exist or incorrect signature: void getNamedCredentials() from the type List<ConnectApi.NamedCredentialList> 

tried this:

ConnectApi.NamedCredentialList nl = ConnectApi.NamedCredentialList.getNamedCredentials(); List <ConnectApi.NamedCredentialList> nl = ConnectApi.NamedCredentialList.getNamedCredentials(); 

How do I call this method correctly ?

sf article I am following: link

2 Answers 2

2

The issue is that you are attempting to call this method on the ConnectApi.NamedCredentialList Class, when the method actually belongs to the ConnectApi.NamedCredential Class.

You should be calling it as:

ConnectApi.NamedCredentialList namedCredList = ConnectApi.NamedCredentials.getNamedCredentials(); 

The NamedCredentialList has a single property namedCredentials, so to loop through these once you have obtained the entire list, you can simply use the following:

for(ConnectApi.NamedCredential nc : ncList.namedCredentials){ //Do logic on the named credentials } 

Alternatively, if you know the Developer Name of the Named Credential you are interested in, you can simply call

ConnectApi.NamedCredential namedCred = ConnectApi.NamedCredentials.getNamedCredential('NamedCredDeveloperName'); 
2
  • Thanks, Callum. How do you loop over namedCredList? Commented Aug 23, 2024 at 14:55
  • No worries, I've updated my answer with the details of that now. Commented Aug 23, 2024 at 15:05
0

Named credential is also exposed by SOQL: select id, DeveloperName from NamedCredential

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.