nadolskimm-max/sf-skills/sf-file-management

Claude Code and agent skill by nadolskimm-max/sf-skills

Trust tier 3
  • community
Source check pending

Checking that the SKILL.md file is still in the repository.

Manages Salesforce files including ContentDocument, ContentVersion, file uploads, attachments, and external storage. Use when uploading files, linking files to records, querying file metadata, managing file permissions, or migrating from Attachments to Files. Do NOT use for general data operations (use sf-data) or metadata XML (use sf-metadata).

Install

npx vskill@latest install nadolskimm-max/sf-skills/sf-file-management

SKILL.md

The same SKILL.md was published earlier as nadolskimm-max/sf-skills/sf-file-management.

File Management

Core Responsibilities

  1. Upload and manage files (ContentDocument / ContentVersion)
  2. Link files to records (ContentDocumentLink)
  3. Query file metadata and content
  4. Manage file permissions and sharing
  5. Migrate legacy Attachments to Files

File Object Model

ContentDocument (file container)
├── ContentVersion (file versions — one per revision)
│ ├── VersionData (actual file binary)
│ ├── Title, FileExtension, ContentSize
│ └── PathOnClient (original filename)
└── ContentDocumentLink (links file to records)
├── LinkedEntityId (Account, Case, etc.)
├── ShareType (V=Viewer, C=Collaborator, I=Inferred)
└── Visibility (AllUsers, InternalUsers, SharedUsers)

Upload File (Apex)

apex
public class FileService {
public static Id uploadFile(Id parentId, String fileName, Blob fileBody) {
ContentVersion cv = new ContentVersion(
Title = fileName.substringBeforeLast('.'),
PathOnClient = fileName,
VersionData = fileBody,
FirstPublishLocationId = parentId
);
insert cv;
return cv.Id;
}
public static void linkFileToRecord(Id contentDocumentId, Id recordId) {
ContentDocumentLink cdl = new ContentDocumentLink(
ContentDocumentId = contentDocumentId,
LinkedEntityId = recordId,
ShareType = 'V',
Visibility = 'AllUsers'
);
insert cdl;
}
}

Query Files

sql
-- Files linked to a record
SELECT ContentDocument.Title, ContentDocument.FileExtension,
ContentDocument.ContentSize, ContentDocument.LatestPublishedVersionId
FROM ContentDocumentLink
WHERE LinkedEntityId = :recordId
-- Latest version of all files
SELECT Id, Title, FileExtension, ContentSize, CreatedDate,
ContentDocumentId, VersionNumber
FROM ContentVersion
WHERE IsLatest = true
ORDER BY CreatedDate DESC
-- File content (download)
SELECT Id, Title, VersionData
FROM ContentVersion
WHERE Id = :versionId

LWC File Upload

html
<template>
<lightning-file-upload
label="Attach Files"
name="fileUploader"
record-id={recordId}
accept={acceptedFormats}
onuploadfinished={handleUploadFinished}
multiple>
</lightning-file-upload>
</template>
javascript
import { LightningElement, api } from 'lwc';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
export default class FileUploader extends LightningElement {
@api recordId;
acceptedFormats = ['.pdf', '.png', '.jpg', '.doc', '.docx', '.xlsx'];
handleUploadFinished(event) {
const files = event.detail.files;
this.dispatchEvent(new ShowToastEvent({
title: 'Success',
message: files.length + ' file(s) uploaded',
variant: 'success'
}));
}
}

File Size Limits

ContextMax Size
Single file upload (UI)2 GB
Apex ContentVersion insert37.5 MB (body in transaction)
REST API file upload2 GB
Email attachment25 MB
Apex Blob variable12 MB (heap limit)

Attachment to Files Migration

apex
public class AttachmentMigrationBatch implements Database.Batchable<SObject> {
public Database.QueryLocator start(Database.BatchableContext bc) {
return Database.getQueryLocator([
SELECT Id, Name, Body, ContentType, ParentId
FROM Attachment
]);
}
public void execute(Database.BatchableContext bc, List<Attachment> scope) {
List<ContentVersion> files = new List<ContentVersion>();
for (Attachment att : scope) {
files.add(new ContentVersion(
Title = att.Name,
PathOnClient = att.Name,
VersionData = att.Body,
FirstPublishLocationId = att.ParentId
));
}
insert files;
}
public void finish(Database.BatchableContext bc) {}
}

Anti-Patterns

Anti-PatternFix
Using Attachment object (legacy)Use ContentVersion / ContentDocument
Large file in Apex Blob variableUse REST API for files > 12 MB
No ShareType on ContentDocumentLinkAlways set ShareType (V, C, or I)
Querying VersionData in bulkQuery metadata first, download individually

Cross-Skill References

  • For Apex file handling: see sf-apex
  • For LWC upload components: see sf-lwc
  • For batch migration: see sf-async-patterns
  • For file security: see sf-security

Security

  • Security scanPassed, 90 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

7-day trend score
0

Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/nadolskimm-max/sf-skills/sf-file-management/badge)](https://verified-skill.com/skills/nadolskimm-max/sf-skills/sf-file-management)

Something wrong with this skill or its page? Tell us.