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
- Create Custom Labels: Select any text in a Salesforce class, right-click, and choose "Create Custom Label." The extension will prompt you for a label name and automatically add the custom label to your project's
CustomLabels.labels-meta.xml
file.
- Automatic Reference Insertion: After creating a custom label, the extension replaces the selected text with a reference to the newly created label, such as
System.Label.<YourLabelName>
.
- Intelligent XML Handling: Ensures that the
CustomLabels.labels-meta.xml
file is properly formatted and adds the new label in the correct location.
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
- 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
Before:
String message = 'Hello, World!';
After running the extension:
String message = System.Label.HelloWorld;
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
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!