---
schema_version: "1"
id: 738055f8671a2cd02f9dc398aec26b5a270289a5a723f4ce6cd72593e9aa57d5
title: "Example: View Uploaded Files in Agentforce Session Tracing"
collection: admin
version: current
locale: en-us
portal_url: https://docs.salesforce.com/admin/current/en-us/ai/264-0-0/agent_file_upload_stdm.md
canonical_url: https://help.salesforce.com/s/articleView?id=ai.agent_file_upload_stdm.htm&release=264.0.0&type=5
source_site: help.salesforce.com
content_type: documentation
content_hash: 177efb32eb37ec315df97644c7113586913c87e3911c41f5d4e6a29ea5c1b021
description: Use this example script to connect the assets uploaded during an agent conversation with the session in Agentforce Session Tracing (STDM).
products:
  - Agentforce
  - Cross Cloud
release: "264"
---
# Example: View Uploaded Files in Agentforce Session Tracing

Use this example script to connect the assets uploaded during an agent conversation with the session in Agentforce Session Tracing (STDM).

### Required Editions

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small edition"><colgroup><col></colgroup><tbody><tr class=""><td class="slds-cell-wrap" style="vertical-align:top;">Available in: Lightning Experience</td></tr><tr class=""><td class="slds-cell-wrap" style="vertical-align:top;">Available in: <strong>Enterprise</strong>, <strong>Performance</strong>, <strong>Unlimited</strong>, and <strong>Developer</strong> Editions. <a href="https://help.salesforce.com/s/articleView?id=ai.agent_setup_explore_types.htm&amp;release=264.0.0&amp;type=5" title="Learn about agent types and default templates for specific clouds and common use cases.">Required add-on licenses vary by agent type.</a></td></tr></tbody></table>

```
WITH
    params AS (
      SELECT                                                                      
        '019f8b59-2e80-77ca-xxxx-xxxxxxxxxxxx' AS session_id
    ),
    interactionsWithMessages AS (
      SELECT
        I.ssot__AiAgentInteractionType__c AS InteractionType,
        I.ssot__StartTimestamp__c AS InteractionStartTime,
        I.ssot__EndTimestamp__c AS InteractionEndTime,
        I.ssot__TopicApiName__c AS TopicName,
        M.ssot__MessageSentTimestamp__c AS MessageSentTime,
        M.ssot__ContentText__c AS ContextText,
        M.ssot__AiAgentInteractionMessageType__c AS InteractionMessageType
      FROM
        ssot__AiAgentSession__dlm AS S
        JOIN ssot__AiAgentInteraction__dlm AS I ON S.ssot__id__c = I.ssot__aiAgentSessionId__c
        JOIN ssot__AiAgentInteractionMessage__dlm AS M ON I.ssot__id__c = M.ssot__aiAgentInteractionId__c
        JOIN params AS p ON S.ssot__Id__c = p.session_id
    ),
    interactionsWithSteps AS (
      SELECT
        I.ssot__AiAgentInteractionType__c AS InteractionType,                
        I.ssot__StartTimestamp__c AS InteractionStartTime,                        
        I.ssot__EndTimestamp__c AS InteractionEndTime,
        I.ssot__TopicApiName__c AS TopicName,
        St.ssot__AiAgentInteractionStepType__c AS InteractionStepType,
        St.ssot__Name__c AS Name,
        St.ssot__InputValueText__c AS InputValueText,
        St.ssot__OutputValueText__c AS OutputValueText,
        St.ssot__StartTimestamp__c AS InteractionStepStartTime,
        St.ssot__PreStepVariableText__c AS PreStepVariableText,
        St.ssot__PostStepVariableText__c AS PostStepVariableText
      FROM
        ssot__AiAgentSession__dlm AS S
        JOIN ssot__AiAgentInteraction__dlm AS I ON S.ssot__id__c = I.ssot__aiAgentSessionId__c
        JOIN ssot__AiAgentInteractionStep__dlm AS St ON I.ssot__id__c = St.ssot__aiAgentInteractionId__c
        JOIN params AS p ON S.ssot__Id__c = p.session_id
    ),
    -- Attachments, joined through their message (attachment.MessageId__c = message.id)
    interactionsWithAttachments AS (
      SELECT                                                                      
        I.ssot__AiAgentInteractionType__c AS InteractionType,
        I.ssot__StartTimestamp__c AS InteractionStartTime,
        I.ssot__EndTimestamp__c AS InteractionEndTime,                            
        I.ssot__TopicApiName__c AS TopicName,
        M.ssot__MessageSentTimestamp__c AS MessageSentTime,                  
        A.SourceName__c AS AttachmentSource,                                      
        A.FileType__c AS AttachmentFileType,
        A.FilePathName__c AS AttachmentFilePath,
        A.ContentDocumentVersionId__c AS AttachmentContentVersionId
      FROM
        ssot__AiAgentSession__dlm AS S
        JOIN ssot__AiAgentInteraction__dlm AS I ON S.ssot__id__c = I.ssot__aiAgentSessionId__c
        JOIN ssot__AiAgentInteractionMessage__dlm AS M ON I.ssot__id__c = M.ssot__aiAgentInteractionId__c
        JOIN AiAgentMessageAttachment_std__dlm AS A ON M.ssot__id__c = A.MessageId__c
        JOIN params AS p ON S.ssot__Id__c = p.session_id
    ),
    unified AS (
      SELECT
        InteractionType, InteractionStartTime, InteractionEndTime, TopicName,
        MessageSentTime, ContextText, InteractionMessageType,
        CAST(NULL AS VARCHAR) AS InteractionStepType,
        CAST(NULL AS VARCHAR) AS Name,
        CAST(NULL AS VARCHAR) AS InputValueText,
        CAST(NULL AS VARCHAR) AS OutputValueText,
        CAST(NULL AS VARCHAR) AS PreStepVariableText,
        CAST(NULL AS VARCHAR) AS PostStepVariableText,
        CAST(NULL AS VARCHAR) AS AttachmentSource,
        CAST(NULL AS VARCHAR) AS AttachmentFileType,
        CAST(NULL AS VARCHAR) AS AttachmentFilePath,
        CAST(NULL AS VARCHAR) AS AttachmentContentVersionId
      FROM interactionsWithMessages
      UNION ALL                                                                   
      SELECT
        InteractionType, InteractionStartTime, InteractionEndTime, TopicName,
        InteractionStepStartTime AS MessageSentTime,
        CAST(NULL AS VARCHAR) AS ContextText,
        CAST(NULL AS VARCHAR) AS InteractionMessageType,
        InteractionStepType, Name, InputValueText, OutputValueText,
        PreStepVariableText, PostStepVariableText,
        CAST(NULL AS VARCHAR) AS AttachmentSource,
        CAST(NULL AS VARCHAR) AS AttachmentFileType,
        CAST(NULL AS VARCHAR) AS AttachmentFilePath,
        CAST(NULL AS VARCHAR) AS AttachmentContentVersionId
      FROM interactionsWithSteps
      UNION ALL
      SELECT
        InteractionType, InteractionStartTime, InteractionEndTime, TopicName,
        MessageSentTime,
        CAST(NULL AS VARCHAR) AS ContextText,
        CAST(NULL AS VARCHAR) AS InteractionMessageType,
        CAST(NULL AS VARCHAR) AS InteractionStepType,
        CAST(NULL AS VARCHAR) AS Name,                                            
        CAST(NULL AS VARCHAR) AS InputValueText,
        CAST(NULL AS VARCHAR) AS OutputValueText,
        CAST(NULL AS VARCHAR) AS PreStepVariableText,
        CAST(NULL AS VARCHAR) AS PostStepVariableText,
        AttachmentSource, AttachmentFileType, AttachmentFilePath, AttachmentContentVersionId
      FROM interactionsWithAttachments
    )
  SELECT
    TopicName, InteractionType, InteractionStartTime, InteractionEndTime,
    MessageSentTime, InteractionMessageType, ContextText,
    InteractionStepType, Name, InputValueText, OutputValueText,
    PreStepVariableText, PostStepVariableText,
    AttachmentSource, AttachmentFileType, AttachmentFilePath, AttachmentContentVersionId
  FROM unified                                                                    
  ORDER BY MessageSentTime ASC
```

#### See Also

- [Agentforce Session Tracing](https://help.salesforce.com/s/articleView?id=ai.generative_ai_session_trace.htm&release=264.0.0&type=5 "Agentforce session tracing captures detailed agent interaction data in a unified data model on Data 360. Build dashboards, reports, and queries on this data to derive insights into agent behavior and trends. Take data-driven action while testing, debugging, and monitoring agents in sandbox or production environments.")