1. What is Agentforce for Developers?
Agentforce for Developers equips developers with AI-powered tools to create Salesforce-centric code, including Apex and Lightning Web Components (LWC). Powered by a custom-trained large language model from Salesforce Research, AFD streamlines repetitive tasks and provides intelligent code suggestions. With AFD handling the routine, developers can focus on solving complex challenges and driving innovation in their projects.
2. Installing and Configuring Agentforce for Developers (AFD)
Installation
You can find Agentforce for Developers (AFD) in the Salesforce Extension Pack (Expanded), available on the Visual Studio Marketplace. Install the pack directly in your Visual Studio Code (VS Code) IDE.
Configuration
After installing AFD, follow these steps to integrate it with your Salesforce organization:
- Connect to Salesforce: Grant AFD the necessary permissions to access your metadata and codebase.
- Enable Telemetry in VS Codesome text
- Open File > Preferences > Settings (Windows/Linux) or Code > Settings > Settings (macOS).
- Search for
salesforcedx-vscode-core.telemetry.enabled
and mark the checkbox to enable telemetry. - Reload the VS Code window to apply your changes.
- Set Java Path: Configure the
salesforcedx-vscode-apex.java.home
setting with the path to your Java installation.
Verification
Check the status icon in the VS Code status bar to confirm that AFD is set up correctly. When active, the icon's background color will match the status bar color, signaling successful integration.
3. Features and Tools
Dev Assistant
The Dev Assistant works like a dependable junior developer, ready to help you with Apex and Lightning Web Components (LWC) code. Click the Agentforce icon in the Activity Bar to open the chat interface and get started. Once activated, Agentforce integrates seamlessly with the context of your open file and ongoing conversation. It analyzes your code and file content in Visual Studio Code, delivering tailored suggestions and insights to improve your workflow.
Wise Wolves’ tip: Keep it concise!
- When coding with Agentforce, break tasks into smaller steps. For example, when creating a Test class, start by creating the Apex class, then move on to implementing the first method, and so forth. Avoid loading all your logic into a single prompt—step-by-step inputs lead to better results and clearer feedback.
Dev Assistant Slash Commands
There are currently three most common commands for all pilots: /explain, /test, and /document.
Wise Wolves’ feedback:
/explain:
This command explains the entire class instead of focusing on a single method./test
: Salesforce has a known issue where this command generates test logic but skips creating test data. It also often defaults to running with system-level permissions (system.runAs)./document:
For long Apex classes, Agentforce may document only parts of the code. To address this, break the class into smaller sections. Select the specific method you want to document, input it into the Dev Assistant, and run the /document command for more precise results.
Inline Auto-Completion
AI-powered autocomplete integrates code suggestions directly into your editor as you write. Inline auto-completions work in Apex and LWC files, including JavaScript, CSS, and HTML, and come enabled by default. You can adjust the completion length to your preference (Short or Long).
Wise Wolves’ Tips:
- Write clear and simple Apex code to get the most accurate autocomplete suggestions.
- Note: LWC suggestions may not fully adhere to best practices at this time.
Agentforce: Generate Code
Open the Command Palette and select Agentforce: Generate Code to create code. Provide a description of what you need, like: "Write a method that takes an account as a parameter and returns all contacts associated with that account."
Agentforce will generate the code based on your request. Review the output and choose:
- Accept to confirm the code,
- Try Again to refine the suggestion, or
- Clear to reset and start over.
Agentforce: Generate A Test
Agentforce provides three ways to generate a test:
- Copy and Paste: Paste your code into the Dev Assistant and ask it to generate a test method.
- Use /test: This command detects the context of the currently open class in your editor and starts creating the test.
- File Selection: Click the icon in the upper-right corner of the editor and select the file you want to test.
If no test class exists, Agentforce will prompt you to create a new test file for the selected class. The chosen option will generate the test method and add it to the appropriate file.
Good to Know: Agentforce analyzes the context of your existing tests to ensure it doesn’t duplicate code when creating new tests.
4. When Should You Use Agentforce?
Agentforce is your go-to tool for a range of development tasks:
1. Explain Code: Understand what a specific piece of Apex code is doing in your Salesforce environment.
2. Write Apex Code: Develop Apex methods when you have clear requirements and a well-defined solution design.
- Note that the scope and complexity of the code needs to be low. AFD is not mature enough for complex tasks.
3. Enforce Best Practices: Get recommendations for Apex coding best practices.
- Note: Best practices for Lightning Web Components (LWC) are not yet supported.
4. Document Your Code: Automatically document Apex, LWC, or Visualforce pages for better readability and clarity.
5. Generate Unit Tests: Quickly create comprehensive unit tests for your Apex code, covering both positive and negative scenarios
Note: Remember to create test data, as Agentforce does not generate it automatically.
Wise Wolves’ Tip: No matter how helpful AI tools like Agentforce can be, always verify the response against best practices. Thoroughly test the output before deploying it or using it in your project.
5. Retrieval-Augmented Generation (RAG): Context-Aware Responses
Agentforce's Retrieval-Augmented Generation (RAG) feature is not yet available, but once it becomes available, we believe it will help you write higher-quality code. In the future, RAG will deliver context-aware responses tailored to your environment. Once activated, RAG will draw from:
- Information about SObjects in your Salesforce DX project,
- The currently active file, and
- Previous chat messages.
By leveraging this context, Agentforce will ensure its responses are accurate and relevant to your prompts.
Important Considerations for Future Use:
To maximize RAG’s effectiveness once it is launched, keeping your project metadata up to date will be crucial. This will involve:
- Running SFDX: Refresh SObjects Definitions to import your org’s metadata as object definitions into your project.
After refreshing, Agentforce will have the necessary context to generate precise, environment-specific responses tailored to your needs.
6. Tips and Tricks for Using AFD Effectively
Craft Clear Prompts: Write specific and detailed prompts to get accurate and relevant suggestions from AFD.
Use Slash Commands: Streamline your workflow with built-in commands like /explain, /test, and /document to target your needs directly.
Refine and Iterate: Review AFD’s suggestions carefully, adjust your prompts, and iterate to achieve better results.
Check out the Effective Prompt Writing page for tips on optimizing your communication with Agentforce.
7. Potential Challenges and How to Overcome Them
Agentforce for Developers (AFD) offers powerful features, but you may encounter some challenges. Here’s how to tackle them effectively:
1. Metadata Awareness
- Challenge: AFD may fail to function correctly without access to your organization’s metadata.
- Solution: Run SFDX: Refresh SObjects Definitions regularly to keep your org’s metadata updated and accessible.
2. Prompt Quality
- Challenge: AFD’s responses heavily depend on the clarity and specificity of your prompts.
- Solution: Craft precise, detailed prompts to avoid generic or incomplete results and get better output.
3. Test Generation Issues
- Challenges: some text
- Selecting too many tests can trigger a token budget exceeded error.
- Selecting fewer tests may produce duplicate test methods.
- AFD doesn’t generate test data alongside test logic.
- Solution: Break the test generation process into smaller steps and manually add test data where needed.
4. Explanation Scope
- Challenge: The
/explain
command explains the entire file in your active editor, even if you only select part of the code. - Solution: Isolate the specific section you want explained in a new file or use a focused prompt for better context.
5. Lightning Web Component (LWC) Limitations
- Challenge: AFD’s LWC generations may not follow current best practices.
- Solution: Use the generated output as a starting point and manually adjust it to align with best practices.
6. Aggregation Queries
- Challenge: AFD does not use aggregate queries when asked to create an aggregation.
- Solution: Provide clear, explicit prompts requesting specific SOQL aggregate functions to guide the results.
7. Documentation Generation
- Challenge: Using
/document
on long code files may produce incomplete results as parts of the code could be truncated. - Solution: Break the code into smaller sections, document each part individually, and merge the results for a complete output.
By proactively addressing these challenges, you can optimize your use of Agentforce and reduce friction in your development process. These strategies will help you make the most of its powerful capabilities.
For more details on known issues, check out the Agentforce Issues Repository.
9. Conclusion
Agentforce for Developers leads the pack in helping you write efficient, high-quality Apex code. It automates routine tasks, delivers smart code suggestions, and simplifies code reviews, letting you focus on innovation and tackling complex challenges. Embrace AFD to enhance your workflow and deliver software solutions that run with the strength of a wolf pack. However, like any powerful tool, it’s essential to use Agentforce intentionally and wisely to maximize its potential and ensure it aligns with your goals.
Learn more by visiting the Agentforce for Developers Overview and Agentforce for Developers Trailhead pages.