agentleFS
rob-alexarob-alexa/claude-skills/skills/salesforce-files-queries/SKILL.md

salesforce-files-queries

Skill1 starsChanged 3 months agoMITView on GitHub

Querying Salesforce Files. TRIGGER when: any ContentVersion or ContentDocumentLink query, counting files or building a file population, files that look missing or under-counted, or ERROR_HTTP_414 on a long IN list. An unfiltered ContentVersion sweep under-returns and its COUNT corroborates the wrong number.

The file

We split this skill into the rules it gives an agent

1 rule. About 0 are common, 0 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈0

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    If a file count came from a ContentVersion sweep, treat it as a floor rather than a total, and re-derive it from ContentDocumentLink before …

    line 52

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

salesforce-files-queries

Query files through ContentDocumentLink, never through a ContentVersion sweep. You need this once you are already querying files, and the failure it prevents is a confidently wrong answer rather than an error.

Point-in-time: measured on a Salesforce production org in 2026. Verify against your own org before asserting any of it as current fact.

An unfiltered sweep under-returns, and its COUNT agrees with the wrong number

SELECT ... FROM ContentVersion WHERE IsLatest = true, run with no other filter, silently returns fewer rows than the org holds, and SELECT COUNT(Id) FROM ContentVersion WHERE IsLatest = true returns the same short number.

The count corroborates nothing. Both queries travel the same access path, so a matching count reads as independent confirmation and is not. That is the whole trap: the natural way to sanity-check the sweep is the one check guaranteed to agree with it.

Measured: the sweep and its COUNT agreed exactly, while pulling the same files filtered by the ContentDocumentId values gathered from ContentDocumentLink returned 99 additional rows. Those 99 are real, present, and IsLatest = true. A targeted WHERE ContentDocumentId IN (...) returns them; the sweep does not.

What to do instead

  • Drive file work from the links. Query ContentDocumentLink for the records you care about (WHERE LinkedEntityId IN (...)), then pull ContentVersion filtered by the resulting ContentDocumentId values. Never take a ContentVersion sweep as the population.
  • A gap between the two is not deleted files. That was the first theory here and it was wrong twice: ContentDocument returned every one of the supposedly missing ids, including under --all-rows. In that case the missing rows clustered into a single category of file, so the sweep did not just undercount, it made a whole category read as zero. Check what the missing rows have in common before theorizing about deletion.
  • Both queries need chunking, and the limit is the URI, not the SOQL. The CLI sends SOQL as a GET parameter, so roughly 1,000 ids in an IN list returns ERROR_HTTP_414: URI Too Long while 400 is comfortable. sf data query has no --bulk flag in the current CLI; it paginates a plain query itself, which is exactly what makes the unfiltered shortcut look attractive in the first place.

Reading the symptom

If a file count came from a ContentVersion sweep, treat it as a floor rather than a total, and re-derive it from ContentDocumentLink before anyone acts on the number. The symptom that should send you here is a category of file that reads as zero, or a total that is close to right and slightly low.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.