StaticResource stores reusable file content for Salesforce applications, including JavaScript libraries, style sheets, images, and ZIP or JAR archives. Visualforce pages, Lightning components, and several configuration types can reference these assets. Static resources are intended for use within your Salesforce org, not as a general-purpose hosting service for unrelated apps or websites.
The type extends MetadataWithContent, inheriting fullName for metadata identity and content for the file payload. In a file-based deployment, the settings XML and the actual file are separate parts of the same component. A valid-looking settings file alone does not supply the resource content.
Key Elements
| Element | What the Element Controls |
|---|---|
fullName |
The resource's metadata name, inherited from the base metadata types. Required when creating, updating, or deleting the resource through Metadata API. The name must start with a letter, cannot end with an underscore, and cannot contain two consecutive underscores. |
content |
The file payload, inherited from MetadataWithContent. Its API transport type is base64Binary. In file-based deployments, the payload is carried in the separate Name.resource file. |
cacheControl |
Required. Allowed values are Private and Public. Public marks the resource with a public caching tag so that third-party delivery clients can cache its content. |
contentType |
Required. Identifies the file's MIME type, the media-type label describing its content, such as text/plain. |
description |
A description of the resource, separate from its name, content type, caching setting, and payload. |
Behavior and Constraints
Public caching is not external hosting. Setting cacheControl to Public supplies a caching designation. It does not make static resources a supported hosting service for unrelated applications or websites. Do not infer an external-hosting capability from the setting's name.
Transport encoding and file contents are different concerns. For API transport, clients encode binary content as base64 before sending it and decode returned content to binary. SOAP clients normally handle that conversion. This requirement does not mean that an on-disk .resource file should contain base64 text; that file carries the actual content or archive.
A payload-only change can affect multiple consumers. Replacing a library, style sheet, or image can change consuming pages, components, and configured images without changing those consumers' metadata. The impact depends on the references actually used, not merely on the possible relationships between metadata types.
Archive consumers can also depend on paths to individual files inside a resource. Keeping the same fullName does not preserve those paths if the archive's contents or directory structure changes. Resource identity, deployment filenames, and internal archive paths are separate things to examine when diagnosing a failure.
Deployment and Retrieval
In the Metadata API file-based package layout, static resources are stored in the staticresources directory. Each resource has two paired files:
-
staticresources/Name.resourcecontains the actual file or archive. -
staticresources/Name.resource-meta.xmlcontains settings such ascacheControl,contentType, anddescription.
A ZIP payload is carried as Name.resource in this layout, rather than as a standalone Name.zip deployment member. The descriptor and payload must belong to the same resource.
StaticResource supports the wildcard * in the package.xml manifest. Use StaticResource as the manifest type name and either the resource name or the wildcard as the member selection.
For direct Metadata API operations, fullName identifies the component for creation, update, and deletion. It is the metadata name, not a runtime record ID.
If deployment reports Required field is missing: content, check whether the payload exists and is correctly paired before changing the XML settings. ANT deployment reports associate this error with a missing .resource file, incorrect payload naming, or a case mismatch between the payload and descriptor filenames. These are reported diagnostic causes, not proof that every occurrence has the same cause.
A successful resource deployment does not establish that every consumer can load every archive entry. For an archive-loading failure, inspect the path used by the consumer as well as the deployed resource name. The reported case-sensitivity issue below concerns filenames inside the ZIP, distinct from the filename pairing used during deployment.
Relationships
Consumers reference static resources either through configuration elements or through expressions and code embedded in their file content. For the code-based consumers below, filedata represents that file content; a reference is not necessarily exposed as a dedicated XML reference element. These relationships identify possible consumers, not confirmed usage of a particular resource.
Referenced By
-
ApexComponent:filedata -
ApexPage:filedata -
LightningBundle:filedata -
LightningWebComponent:filedata -
ConversationVendorInfo:customIcon -
QuickAction:icon -
CustomSite:favoriteIcon,serverIsDown -
EmbeddedServiceConfig:resource -
EmbeddedServiceMenuSettings:resource -
LiveChatButton:inviteImage,offlineImage,onlineImage -
LiveChatDeployment:brandingImage,mobileBrandingImage
Documentation Inconsistencies
The official declarative XML sample omits cacheControl, although the field definition marks it required. Include an explicit Private or Public value rather than treating that sample as a complete deployment descriptor.
Reported Issues
-
A missing-content error can come from the deployment files rather than an omitted XML setting. In an ANT deployment discussion spanning 2016-2020, respondents associated
Required field is missing: contentwith absent payload files, incorrect payload naming, and mismatched filename case. Check the exact pairing ofName.resourceandName.resource-meta.xml. See the missing-content deployment discussion. -
An existing archive can still fail to supply a file requested by an LWC. A 2021 troubleshooting answer identified case-sensitive filenames inside ZIP resources as a possible cause when a resource loaded in Aura and Visualforce but not in a Lightning web component. The discussion did not establish a confirmed root cause for the reported failure. This check concerns the internal archive path, not just the resource's
fullName. See the LWC archive-loading discussion. -
A post-install query failure can involve runtime sharing context rather than metadata deployment support. In a 2021 managed-package report, querying the runtime
StaticResourcesObject frominherited sharingclasses producedsObject type 'StaticResource' is not supported.The author reported resolving the failure by isolating the query in awithout sharingclass. This is a conditional runtime-access report, not a general requirement to remove sharing or a restriction on deployingStaticResourcemetadata. See the post-install query discussion.
Common Questions
Why does StaticResource deployment say "Required field is missing: content"?
Reported ANT deployment causes include a missing payload, an incorrectly named payload, or different filename case between Name.resource and Name.resource-meta.xml. Check both files and their exact pairing before treating the error as a missing XML setting.
Should a .resource file contain base64 text?
Not because of the API encoding requirement. Base64 applies to the inherited content field during API transport. In a Metadata API file-based deployment, the .resource file contains the actual file or archive, separate from its settings XML.
Does cacheControl Public let me host files for another website?
No. Public marks the resource for public caching by third-party delivery clients. Static resources remain intended for use within the Salesforce org, not as general-purpose hosting for unrelated websites or apps.
Why can an LWC fail to load a file when the static resource exists?
The consumer may depend on a particular path inside the archive, not merely on the resource's existence. A community answer identifies filename case inside ZIP resources as a possible cause, but it did not confirm the cause of that reported failure.