---
schema_version: "1"
id: 684e388d4f63c9e1af975bb71c20b0383ac4e3a34bd8b10e2cfdf8ee1b0eacb8
title: Share Temporary Access to Records in Advanced Approvals
collection: admin
version: current
locale: en-us
portal_url: https://docs.salesforce.com/admin/current/en-us/ind/264-0-0/approvals_share_records_using_triggers.md
canonical_url: https://help.salesforce.com/s/articleView?id=ind.approvals_share_records_using_triggers.htm&release=264.0.0&type=5
source_site: help.salesforce.com
content_type: documentation
content_hash: b880f1f3a16d8351e408d490ec8f4f864e7606be2541c87e0fceb5bc9415ae69
description: Share temporary access to related records with your approvers by setting up triggers. After the approval action is complete, use a trigger to withdraw the record access.
products:
  - Revenue Cloud
release: "264"
---
# Share Temporary Access to Records in Advanced Approvals

Share temporary access to related records with your approvers by setting up triggers. After the approval action is complete, use a trigger to withdraw the record access.

When you submit a record for approval, the approver must have access to the record’s related object to perform actions on the approval request. If your object’s internal organization-wide sharing default is Private, you can use a trigger to create a share object that grants access to the approver. After the record is approved, you can withdraw the record access by using a trigger to delete the share record.

1. Create an Apex trigger to share access to a record's related object. Under Security, select the profile of your approver. See [Define Apex Triggers](https://help.salesforce.com/s/articleView?id=platform.code_define_trigger.htm&type=5&language=en_US).
    
    ![Tip](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-ind-revenue-264-0-0-production-enus/91ca99c6-d5c8-4986-b961-c6b7801e0d0d/images/icon_tip.png)
    
    Tip
    
    If you're sharing access to a custom object, you can [create an Apex sharing reason](https://help.salesforce.com/s/articleView?id=platform.security_apex_sharing_reasons.htm&type=5&language=en_US) and include it in the trigger. An apex sharing reason restricts the record access to your specific use case.
2. Create an Apex trigger to delete the share record and revoke the record access after the approval request is complete. Under Security, select the profile of your approver.
    
    You can customize the sample code snippet to suit your specific use case.
    
    ```java
    trigger AWIUpdate on ApprovalWorkItem(after update) {
    List<ApprovalWorkItem> awiList = new List<ApprovalWorkItem>();
    // Get the related opportunities for the accounts in this trigger
    awiList = [SELECT Id, RelatedRecordId, AssignedToId FROM ApprovalWorkItem WHERE Id IN :Trigger.new];
    
    for (ApprovalWorkItem awi : awiList) {
    // Use the related record id, to delete the share record created for the user
    
    Id relatedRecordId = awi.RelatedRecordId;
    Id assignedToId = awi.AssignedToId;
    
    SObjectType relatedRecordType = relatedRecordId.getSObjectType();
    if (relatedRecordType.getDescribe().isCustom()) {
    Map<String, Schema.SObjectType> tokens = Schema.getGlobalDescribe();
    String relatedRecordShareName = relatedRecordType.getDescribe().getName().removeEnd('__c') + '__Share';
    if(tokens.containsKey(relatedRecordShareName)) {
    // Share object exists
    SObject[] customShare = Database.query('SELECT Id FROM '
    + relatedRecordShareName + ' WHERE '
    + ' RowCause = \'AdvancedApprovalTriggerShareReason__c\' '
    + ' AND ParentId = :relatedRecordId'
    + ' AND UserOrGroupId = :assignedToId');
    } else {
    // OWD is Public Read Write
    }
    }
    }
    }
    ```