Skip to main content

How to Fix "You Don't Have Permission to View This Data" in Salesforce

In plain words: The error System.UnexpectedException: You don't have permission to view this data happens when Salesforce tries to fetch information from an external system but is blocked. This is almost always caused by missing access rights, broken passwords, or misconfigured connection settings—not bad code.

Connecting Salesforce to external platforms is a great way to build a unified system. However, when linking to external databases, OData services, or third-party APIs, communication can sometimes break down. If you run into this permission exception, it means the digital handshake between Salesforce and the outside provider has failed, and access was denied.

Key Points

  • It's a setup issue: This error is rarely caused by typos in your Apex code. It is almost entirely driven by security configurations.
  • Profile limits: The active user usually lacks specific permissions to view the connected External Data Source.
  • Auth matters: Expired OAuth tokens or outdated passwords in Named Credentials are the most frequent culprits.

Frequently Asked Questions

Does this error mean my Apex code is broken?

No. While the error surfaces in Apex, the root cause is environmental. It simply means your code tried to execute an integration callout, but Salesforce's security layers (or the external server's security) blocked the attempt.

Are Named Credentials involved?

Yes, absolutely. Salesforce strongly recommends using Named Credentials to manage authentication securely. If the underlying Named Credential is not shared with the user, or if the authentication token has expired, this error will trigger immediately.

Why Does This Error Happen?

Understanding the "why" makes troubleshooting much faster. Here are the most common triggers:

  • Profile and Permission Set Gaps: The user experiencing the error does not have access to the specific External Data Source in their Profile or Permission Set.
  • Broken Authentication: The static password, API key, or OAuth token used to connect to the external system has expired, been changed, or was revoked by the external provider.
  • Configuration Drift: The external endpoint URL has changed, or the target system updated its security protocols, leaving your Salesforce configuration out of date.

Step-by-Step Troubleshooting Guide

Follow these real-world steps to systematically hunt down and fix the permission block:

Step 1: Audit User Permissions
Navigate to the user's Profile or Permission Set. Look for the External Data Source Access section. Ensure the target integration is explicitly enabled. If you don't have admin rights, ask your Salesforce Administrator to verify these visibility settings for you.
Step 2: Refresh the Authentication
Go to Setup > Named Credentials (or External Data Sources). Check the authentication status. If the integration uses OAuth, click to re-authenticate and grant access again. If it uses a static password, verify the credentials are still accurate by logging into the external system directly.
Step 3: Validate Connection Settings
Check for subtle typos. Ensure the endpoint URL, username, and client secrets are perfectly accurate. Sometimes, endpoints are updated from http to https without notice, which can sever the connection.
Warning for Per-User Authentication: If your integration requires users to authenticate individually, and you recently changed your Salesforce login password, check your external credentials. You may need to navigate to your Personal Settings and re-authenticate the external system to generate a fresh token.

When to Involve Your Salesforce Admin

Some security layers are locked down for safety. If the steps above don't clear the error, ask your administrator to step in and:

  • Verify the Auth. Provider is configured with the correct scopes and consumer secrets.
  • Review network settings, such as Login Flows or IP restrictions, especially if the external data source lives on an on-premise server behind a firewall.
  • Run a trace using Debug Logs. By filtering for "System" and "Callout," they can inspect the exact raw error response coming back from the external server.
360 Card: Troubleshooting Checklist
  • Permissions: Does the User Profile actually have access to the External Data Source?
  • Authentication: Is the OAuth token valid, or did the password recently expire?
  • Endpoint: Is the target URL currently live and reachable from Salesforce?
  • Configuration: Did the third-party system recently update its API or security rules?
Core Takeaway: Don't rewrite your code just yet! Authentication errors are usually temporary configuration hiccups. Start by verifying your Named Credentials and Profile permissions. In over 90% of cases, refreshing the token or checking a forgotten checkbox solves the issue instantly.