Sub topic 10
Verifying what the integration user can do
This chapter assumes you have already created the integration user, assigned a permission set, and set up OAuth. It also assumes you are comfortable with SOQL and the Salesforce CLI. Here you confirm that the user can do what it should and nothing more.
Why verify
A permission set that looks correct in Setup can still grant extra access. The user may hold another permission set, a profile may add rights, or a sharing rule may expose more records than you expected. Verification checks the effective result, not the intended design.
Run each check below in a sandbox first. Test both sides: what the user can do and what it must be denied.
Step 1: List every assignment
Start by listing everything assigned to the user. Every user has a profile-owned permission set, which appears with IsOwnedByProfile set to true.
SELECT PermissionSet.Name, PermissionSet.Label, PermissionSet.IsOwnedByProfile
FROM PermissionSetAssignment
WHERE AssigneeId = '005XXXXXXXXXXXXXXX'Expect two rows: the profile-owned entry and your Integration_Account_Read permission set. Any other row is extra access. Find out why it is there before you continue.
Step 2: Inspect object permissions
Next, check what each permission set grants on objects.
SELECT SobjectType, PermissionsRead, PermissionsCreate, PermissionsEdit, PermissionsDelete, PermissionsViewAllRecords, PermissionsModifyAllRecords
FROM ObjectPermissions
WHERE Parent.Name = 'Integration_Account_Read'For the example permission set, you should see one row for Account with only PermissionsRead set to true. These flags need the closest look:
PermissionsDelete: the integration rarely needs it.PermissionsViewAllRecords: it bypasses sharing for that object.PermissionsModifyAllRecords: it bypasses sharing and allows edits and deletes.
Run the same query for the profile-owned permission set too, because the profile can also grant these flags.
Step 3: Test as the integration user
Queries on permission records show what is configured. A real login shows what works. Log in with the JWT bearer flow and run a query the user should be allowed to make.
sf org login jwt \
--client-id "$SF_CLIENT_ID" \
--jwt-key-file server.key \
--username [email protected] \
--instance-url https://test.salesforce.com \
--alias integration-sandbox
sf data query \
--target-org integration-sandbox \
--query "SELECT Id, Name, Industry FROM Account LIMIT 5"The query should return rows. Then run the same command against an object the user should not reach, such as Contact or Opportunity. A correct setup fails with an error such as sObject type 'Contact' is not supported. That message means the user has no read access to the object. A denial is a pass.
Also try a field the permission set does not cover, for example AnnualRevenue on Account. The query should fail with a "No such column" error, because the user has no field-level access to it.
Test writes
Try a create or update as well. In the example, both must fail, because allowCreate and allowEdit are false.
sf data create record \
--target-org integration-sandbox \
--sobject Account \
--values "Name='Should Fail'"The command must return an insufficient access error. If the record is created, find which permission set or profile granted the right.
Step 4: Review login activity
Last, confirm that logins come from the places you expect.
SELECT LoginTime, SourceIp, LoginType, Status, Application
FROM LoginHistory
WHERE UserId = '005XXXXXXXXXXXXXXX'
ORDER BY LoginTime DESC
LIMIT 20Check that each SourceIp matches your integration host and that Application names your connected app. Your test logins from the CLI will appear here too.
Common errors
| Symptom | Likely cause |
|---|---|
| Query on a permitted object returns zero rows | The sharing model hides the records, and the user has no View All |
| Query on a forbidden object succeeds | An extra permission set or the profile grants access |
| Login fails with `invalid_grant` | The user is not pre-authorized for the connected app, or the certificate does not match |
| A field returns nothing or errors | Field-level security was not granted in the permission set |
Exercise
After logging in as the integration user, a query on Account returns the rows you expect, but a query on Opportunity also succeeds. Which two SOQL checks do you run to find the cause?
Show answer
First, query PermissionSetAssignment for the user to list every permission set, including the profile-owned one. Then query ObjectPermissions for each of those permission sets, filtering on Opportunity, to find which one grants read access. Remove or tighten that grant, then repeat the login test.