Sub topic 8
Granting access with permission sets
This chapter assumes you can create a permission set and assign it to a user. It also assumes you have an external data source and at least one external object, such as Product__x, created with Validate and Sync. If you have not done that yet, finish the previous chapters first.
Generating an external object does not make it usable. A new external object, and every field created for it, starts with no access for anyone except administrators who have broad permissions. You decide who can see which external data, and you do it with permission sets.
What controls access to external data
Several settings work together. A user needs all of the ones that apply to their case, and a gap in any one of them produces an empty list, a missing field, or an authentication error.
| Layer | What it controls | Where you set it |
|---|---|---|
| Object permissions | Whether the user can read, create, edit, or delete rows of the external object | Permission set, Object Settings |
| Field permissions | Which fields of the external object the user can see or change | Permission set, Object Settings |
| External data source access | Whether the user can authenticate to the data source (per-user authentication) | Permission set, External Data Source Access |
| External credential principal access | Whether the user can use the credentials a named credential relies on | Permission set, External Credential Principal Access |
| Tab visibility | Whether the external object's tab appears | Permission set, Object Settings |
Permission sets are additive. A user's effective access is the union of their profile and every permission set or permission set group assigned to them. Prefer permission sets over editing profiles. You can then give one group of users read access to product data without touching the profile they share with everyone else.
Object permissions
Open Setup > Permission Sets, choose or create a permission set, then open Object Settings and select the external object. The permissions you can set are Read, Create, Edit, and Delete.
Read is the one most users need. The other three only have an effect if the external data source is writable. Writable external objects are covered in a later chapter. If the data source is read-only, granting Edit does not make writes work, so leave it off. That keeps the permission set honest about what the integration supports.
External objects do not use Salesforce's record-level sharing model. There is no owner, no organization-wide default to tune, and no sharing rules for the rows. Salesforce does not decide which rows a user may see. The external system decides, based on the credentials the callout uses. Plan for this when you choose between the two authentication models:
- Named principal. Every Salesforce user who passes the permission checks reads the data as the same external identity. The external system sees one user, so it cannot filter rows per person. Everyone with Read access sees everything that identity can see.
- Per user. Each Salesforce user authenticates with their own external identity, so the external system can apply its own row-level rules.
Field permissions
Field permissions work as they do on any other object. Each field gets Read Access and Edit Access, and the permission set's Object Settings page lists every field.
Some practical points:
- Standard fields such as
ExternalIdandDisplayUrlare part of the external object. Check their access explicitly instead of assuming it. - A field a user cannot read is left out of the page layout, list views, and query results.
- Edit Access only matters on writable external objects, and only for fields the external system lets you write.
- Fields added later are not granted automatically. If the external schema changes and you run Validate and Sync again, new custom fields appear on the object with no permissions. Update your permission sets afterward.
That last point causes many support questions. After a sync, the new column exists but nobody sees it, including users whose permission set grants everything else on the object.
Access to the data source and credentials
Object and field permissions are not enough when the connection needs a user identity.
With per-user authentication on the external data source, grant the data source in the permission set under External Data Source Access. Users with that access can then enter their own credentials from their personal settings, in the section for external data authentication.
With the named credential and external credential model, access flows through the external credential. Add the principal to the permission set under External Credential Principal Access. Without it, queries fail with an authentication or authorization error even though the user can open the object's tab.
Defining the access as metadata
You can keep a permission set in source control and deploy it. This example grants read-only access to Product__x, two of its fields, the data source, and the tab. Adjust the names to match your org.
<?xml version="1.0" encoding="UTF-8"?>
<PermissionSet xmlns="http://soap.sforce.com/2006/04/metadata">
<label>Product Catalog Reader</label>
<description>Read-only access to the external product catalog.</description>
<hasActivationRequired>false</hasActivationRequired>
<externalDataSourceAccesses>
<enabled>true</enabled>
<externalDataSource>Product_Catalog</externalDataSource>
</externalDataSourceAccesses>
<objectPermissions>
<allowCreate>false</allowCreate>
<allowDelete>false</allowDelete>
<allowEdit>false</allowEdit>
<allowRead>true</allowRead>
<modifyAllRecords>false</modifyAllRecords>
<object>Product__x</object>
<viewAllRecords>false</viewAllRecords>
</objectPermissions>
<fieldPermissions>
<editable>false</editable>
<field>Product__x.Name__c</field>
<readable>true</readable>
</fieldPermissions>
<fieldPermissions>
<editable>false</editable>
<field>Product__x.Price__c</field>
<readable>true</readable>
</fieldPermissions>
<tabSettings>
<tab>Product__x</tab>
<visibility>Available</visibility>
</tabSettings>
</PermissionSet>If you use the named credential model, add an externalCredentialPrincipalAccesses block instead of, or alongside, the data source entry. Its principal value combines the external credential name and the principal name.
Checking access from Apex
Apex can test what the running user may do, which is useful in a controller that must degrade gracefully instead of failing.
Schema.DescribeSObjectResult objectInfo = Product__x.SObjectType.getDescribe();
Boolean canReadObject = objectInfo.isAccessible();
Boolean canReadPrice = Schema.SObjectType.Product__x.fields.Price__c.isAccessible();
if (!canReadObject || !canReadPrice) {
System.debug('Current user cannot read product prices.');
} else {
List<Product__x> products = [
SELECT ExternalId, Name__c, Price__c
FROM Product__x
LIMIT 5
];
System.debug(products.size() + ' products returned');
}A describe check confirms object and field permissions only. It does not confirm that the user's credentials work, so a query can still fail with a callout error. Catch the exception when a failure is plausible.
Common errors and how to read them
- The tab is missing. Read permission is granted, but tab visibility is not. Set the tab to Available or Visible in the same permission set.
- The list view is empty but no error appears. Check field permissions and whether the list view filters on a field the user cannot read. Also confirm the external system returns rows for the identity in use.
- A field is blank for one user. That user's permission sets lack Read Access on it.
- An authentication error appears for some users only. They are missing the data source or principal grant, or they have not entered their own credentials under per-user authentication.
- Edit works in the UI for an admin but not for others. The admin's profile has broader permissions. Test with a user who has only the permission set you built.
A sound way to structure access
Create one permission set per business capability, not one per user group. For example, make Product Catalog Reader for read access and Product Catalog Editor for writes. Combine them with other permission sets in a permission set group when a role needs several. Keep the credential grant in the same set as the object grant, so a user who is assigned the set receives a working configuration. After every Validate and Sync, review the new fields, and test as a user with only the intended permission sets.
Exercise
A user has Read permission on Product__x and the tab is visible, but opening the tab shows an authentication error. The data source uses per-user authentication. What is the most likely missing grant, and what must the user do besides receiving it?
Show answer
The permission set lacks External Data Source Access for the data source. After it is granted, the user must also enter their own credentials for that data source in their personal external authentication settings, because per-user authentication uses each person's own external identity.
Exercise
You run Validate and Sync after the external system adds a Discount_c column. Users who previously saw every field cannot see Discount_c. Why, and how do you fix it?
Show answer
New fields are not added to existing permission sets. Edit the relevant permission sets under Object Settings for the external object and enable Read Access (and Edit Access only if the object is writable and the field can be written) for Discount__c.