prettier-plugin-xml-salesforce
v1.0.0
Published
A Prettier plugin for formatting XML files in Salesforce projects
Downloads
171
Maintainers
Readme
prettier-plugin-xml-salesforce
This plugin extends the functionality of the plugin @prettier/plugin-xml, providing custom formatting for Salesforce XML files, specifically handling <flow> elements and formula tags.
This plugin also support (re-exports) all the standard features of @prettier/plugin-xml: see documentation.
Problem Statement
Flow Tags
Salesforce Permission Set XML files may contain <flow> tags which grant access to specific flows. These tags require to be formatted as single-line elements to maintain proper XML structure by design. Unfortunately, the default @prettier/plugin-xml does not handle this correctly, often breaking the intended single-line format.
Example:
<PermissionSet>
<flow>SomeFlowAccess</flow>
</PermissionSet>easily becomes:
<PermissionSet>
<flow>
SomeFlowAccess;
</flow>
</PermissionSet>This breaks the deployment of the *.permissionset-meta.xml files.
Formulas
Salesforce Formula Fields and Validation Rules often contain complex formula expressions. These formulas need to be formatted in a canonical way to ensure readability and maintainability. Unfortunately, there is no default formatting for these formulas, so they must be formatted manually or retriaved and left as-is by default.
Example:
<CustomField>
<formula>AND(
ISPICKVAL ( Status__c , "quot;Active"quot;),
NOT( ISBLANK( End_Date__c) ))
</formula>
</CustomField>This plugin formats Salesforce formula tags in a canonical way:
<CustomField>
<formula>
AND(
ISPICKVAL(Status__c, "Active"),
NOT(ISBLANK(End_Date__c))
)
</formula>
</CustomField>This allows easier readability and maintainability of complex Salesforce formulas within XML files.
Salesforce Limitations
Formula fields in Salesforce have a character limit, and overly complex formulas may exceed this limit when formatted with additional line breaks and indentation. Developers should be aware of this limitation when using the plugin to format formula tags.
| Limit | Value | | --------------- | --------------- | | Formula Field | 4000 characters | | Validation Rule | 3900 characters |
Usage
Prettier Configuration
In the Prettier configuration file (e.g., .prettierrc), you can enable the plugin and its custom options as follows:
{
"plugins": ["prettier-plugin-xml-salesforce"],
"xmlFlowSingleLine": true,
"xmlFormulaFormat": true
}This plugin should be used instead of the default @prettier/plugin-xml when working with Salesforce XML files to ensure proper formatting of <flow> tags (in permission sets) and formula tags.
Prettier Options
| Option | Type | Default | Description |
| ----------------- | ------- | ------- | ---------------------------------------------------------------- |
| xmlFlowSingleLine | boolean | true | Format <flow>...</flow> as a single line and drop trailing ; |
| xmlFormulaFormat | boolean | false | Canonically format Salesforce formula tags |
