---
template: "page.peb"
title: "Attach File Skill"
description: "Use the Attach File skill to save generated charts, markdown, HTML, and plain-text files directly onto the current Salesforce record."
displayName: "Attach File Skill"
category: "skills"
contentType: "reference"
audience: "admin"
tags: "skills,files,attachments,agents,salesforce"
section: "skills"
seoTitle: "Attach File Skill"
seoDescription: "Learn how Salesforce admins can use the Attach File skill to save generated chart images, markdown, HTML, and plain-text files directly to Salesforce records."
---

## Attach File Skill

## Overview
Use the Attach File skill when your agent should save a generated file directly to the current Salesforce record as a Salesforce File.

This is the right fit when the user wants the file itself, not a PDF wrapper.

## Who This Is For
Salesforce admins, solution architects, RevOps teams, and service operations teams who want agents to leave behind reusable files on Accounts, Opportunities, Cases, and similar records.

## What The Skill Can Attach
- chart images generated earlier in the same dialogue
- markdown runbooks
- HTML summaries
- plain-text notes or handoff files

## Best Use Cases
- attach a rendered chart PNG to an Account, Opportunity, or Case
- create a markdown troubleshooting runbook for a support record
- save an HTML handoff summary for internal teams
- attach a plain-text checklist or action summary to the current record

## How It Works
The skill supports two safe source patterns:

- a file artifact that was already produced earlier in the same dialogue
- inline text content created by the agent during the current response

This means the skill is designed for trusted, in-conversation outputs. It is not a general-purpose remote file fetcher.

## Safety And Scope
Attach File is intentionally scoped to the current dialogue and current Salesforce record.

That means:

- the agent should only attach artifacts that already exist in the same dialogue
- the agent should not invent S3 keys or signed URLs
- the agent should not try to browse for unrelated files
- the agent should only attach to the current record context in v1

## When To Use Attach File vs. Generate PDF
- Use `attach_file` when the user wants the raw file saved to Salesforce.
- Use `generate_pdf` when the user wants a polished downloadable document.
- Use `render_chart` with direct chart attachment when the user wants the chart PNG itself attached to the record.

## Prompt Guidance Snippets
Use snippets like these in your custom agent system prompt.

### Attach A Generated Markdown File

```text
When the user wants a runbook, checklist, or summary file saved on the current Salesforce record, create the file content and call attach_file.
Use markdown for structured runbooks and text/html only when the user clearly needs HTML.
```

### Attach A Prior Chart Artifact

```text
When the user wants a chart file attached to the current Salesforce record, first create the chart and then attach that generated artifact to the record.
Do not invent storage keys or external file URLs.
```

## Example Agent Behaviors

### Example: Support Runbook
User request:

```text
Create a markdown runbook for this case and attach it to the record.
```

Good agent behavior:

- generate the markdown content
- call `attach_file`
- attach the markdown file to the current Case

### Example: Attach A Chart Image
User request:

```text
Create a bar chart of cases by priority and attach the chart image to this account.
```

Good agent behavior:

- create the chart first
- attach the resulting PNG to the current Salesforce record
- avoid wrapping it in a PDF unless the user asked for a report

## Tips For Better Results
- Tell the agent what kind of file you want: markdown, HTML, plain text, or chart image.
- Tell the agent whether the file should be concise or detailed.
- Keep the request tied to the current record when you want the file saved in Salesforce Files.
- Ask for a PDF only when you want a formatted document instead of the raw generated file.

## Troubleshooting
- No file was attached: make sure the agent had current Salesforce record context.
- The wrong file type was attached: tell the agent explicitly whether you want markdown, HTML, plain text, or a chart image.
- The agent tried to use a PDF when you wanted the raw file: update the prompt to tell it to attach the file directly to the record instead of calling `generate_pdf`.
- The agent referenced a file that does not exist: make sure it first creates the artifact in the same dialogue before trying to attach it.
