Create New Custom Label Extension
The "Create New Custom Label" extension for Visual Studio Code allows Salesforce developers to easily create custom labels directly from selected text within a Salesforce class. This extension streamlines the process of defining custom labels by automating the creation and insertion of label references.
Features
- Supports JavaScript and Apex: Works seamlessly with both JavaScript (.js) and Apex (.cls) files.
- Automatic Import Insertion: Automatically inserts the import statement for custom labels in JavaScript files.
- Label Validation: Prevents duplicate labels from being created in
CustomLabels.labels-meta.xml
.
- User-Friendly Prompts: Prompts for the label name and optional categories.
Requirements
- Visual Studio Code
- Salesforce Extension Pack (recommended)
- A Salesforce DX project with the
force-app/main/default/labels/CustomLabels.labels-meta.xml
file present
Installation
You can install the extension from the Visual Studio Code Marketplace.
- Open Visual Studio Code
- Go to the Extensions view (Ctrl+Shift+X or Cmd+Shift+X on macOS)
- Search for "Create New Custom Label"
- Click Install
Usage
- In an Editor, select the text you want to convert to a custom label (must be enclosed in quotes)
- Right-click and choose "Create Custom Label" from the context menu
- Enter a name for your custom label
- Optionally enter categories for the label
- The extension will create the custom label and update your code
Example
In Apex Class File:
Before:
String message = 'Hello, World!';
After running the extension:
String message = System.Label.HelloWorld;
In JS File::
Before:
const some_awesome_variable = 'Some Amazing Text';
After running the extension:
import INCREDIBLY_FAST_LABEL_GEN from '@salesforce/label/c.INCREDIBLY_FAST_LABEL_GEN';
const some_awesome_variable = INCREDIBLY_FAST_LABEL_GEN;
Extension Settings
This extension does not contribute any additional settings.
Known Issues
- If the
CustomLabels.labels-meta.xml
file is missing or corrupted, the extension may fail to create the custom label.
Release Notes
1.0.0
This release of the "Create New Custom Label" extension.
- Initial release of the "Create New Custom Label" extension.
- Added support for both JavaScript and Apex files.
- Automatic insertion of import statements for custom labels in JavaScript files.
- Validation to prevent duplicate label creation in
CustomLabels.labels-meta.xml
.
0.0.1
Initial release of the "Create New Custom Label" extension.
- Create custom labels from selected text
- Update CustomLabels.labels-meta.xml
- Replace text with custom label reference
- Support for optional categories
Contributing
If you find any issues or have suggestions for new features, feel free to open an issue or submit a pull request.
Working with Markdown
You can author your README using Visual Studio Code. Here are some useful editor keyboard shortcuts:
- Split the editor (
Cmd+\
on macOS or Ctrl+\
on Windows and Linux)
- Toggle preview (
Shift+Cmd+V
on macOS or Shift+Ctrl+V
on Windows and Linux)
- Press
Ctrl+Space
(Windows, Linux, macOS) to see a list of Markdown snippets
For more information:
Enjoy using the extension!