20

I'm looking into using Named Credentials (spring '15) to simplify apex callouts to an external web service. I actually thought, based on the documentation, that this would help, and I'm referring correctly to the Named Credential in my code and have also given my profile access to the NC, but I'm faced with this error when I do the callout:

System.UnexpectedException: You don't have permission to view this data. Ask your administrator to set up authentication for the external data source

This seems to say that NC are tied to the use of External Data Source, which is absolutely unrelated to what I want to do, and the documentation doesn't mention that they are a requirement. Have any of you run into this error when testing out Named Credentials?

4 Answers 4

24

The error occurs if your named credential is configured to use per-user authentication but the currently logged in user that is trying to use the named credential (or their administrator) has not added their credentials to the Authentication Settings for External Systems section (located under My Settings) for that named credential.

The error message mentions external data sources because under the hood, the features share a lot of the same code. But it is confusing, and a bug.

1
  • 2
    yeah, I figured as much that this was a wrong functional error message. i filed a bug report (case) with Salesforce so they know about it.
    – akarnid
    Dec 17, 2015 at 13:56
3

FWIW I think this may also get thrown as an error when the password is incorrect, or it could just be the system gets into a 'bad state'. I ended up on this Q/A after seeing the exact same message, "Authentication Settings for External Systems" were empty, and the Salesforce setup UI wouldn't let me delete the named credential - no error, just no UI feedback at all.

I edited the credential, changing it away from "Named Principal", then back to "Named Principal" and re-entered the password. After saving once more, it started working.

3

When I deploy a Named Credentials using sfdx force:source:deploy command to a sandbox, When I run the test, I had the same error message as @akarnid.

I went to that Named Credentials, Click "Edit", but actually didn't edit anything, just "Save" it. Then it works.

I deployed it again, it still works.

1
  • Thanks for sharing. your workaround worked for my use case
    – Shamina
    Nov 8, 2022 at 14:44
0

Thanks for the answer, just to help. In my tests, what Lawrence pointed is strictly necessary and those are the credentials that will be used by Salesforce to authenticate to the remote site. Those defined on the named credenctial (per user password authentication) are not used. If you want to verify that, use any wrong credentials on the named credentials definition, but use the correct ones on the Authentication Settings for External Systems section (located under My Settings) and you will see as the connection is established correctly.

You must log in to answer this question.

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