Update and Deploy Permissions

Update a permission set to ensure that the function we create can access data in our Salesforce org. A permission set is a collection of settings and permissions that give users and apps access to various tools and data in Salesforce.

Update the Functions Permission Set

When you connect your org to Salesforce Functions via the Functions Setup page, Salesforce creates a Functions permission set with minimal permissions. Update that permission set to give your function access to the Account object.

To update the Functions permission set, add the file force-app/main/default/permissionsets/Functions.permissionset-meta.xml, with contents:

<?xml version="1.0" encoding="UTF-8"?>
<PermissionSet xmlns="http://soap.sforce.com/2006/04/metadata">
    <hasActivationRequired>true</hasActivationRequired>
    <label>Functions</label>
    <objectPermissions>
        <allowCreate>true</allowCreate>
        <allowDelete>false</allowDelete>
        <allowEdit>true</allowEdit>
        <allowRead>true</allowRead>
        <modifyAllRecords>false</modifyAllRecords>
        <object>Account</object>
        <viewAllRecords>false</viewAllRecords>
    </objectPermissions>
</PermissionSet>

These permissions allow a running function in a compute environment connected to your org to access the Account object.

Deploy the Functions Permission Set

Use project deploy start with the --ignore-conflicts flag to deploy your changes to the Functions permission set to your scratch org:

sf project deploy start --ignore-conflicts --target-org MyOrgAlias
  • --ignore-conflicts Runs the deploy command even if conflicts exist.
  • --target-org A username or alias for the target org. Overrides the default target org.

Outputs:

Deploying v59.0 metadata to test-1234dbzjb@example.com using the v60.0 SOAP API.
Deploy ID: 0Af6t00000jWn
Status: Succeeded | ████████████████████████████████████████ | 1/1 Components | Tracking: 1/1

Deployed Source
========================================================================================================
| State   Name      Type          Path
| ─────── ───────── ───────────── ──────────────────────────────────────────────────────────────────────
| Created Functions PermissionSet force-app/main/default/permissionsets/Functions.permissionset-meta.xml

tip: In VS Code, from the Command Palette, choose SFDX: Push Source to Default Scratch Org.