Dev Agent Context
Context is one of Dev Agent's most powerful features, letting you seamlessly bring information into your Salesforce development conversations. Instead of copying and pasting code, error messages, or documentation, you can simply reference them directly to give Dev Agent a more complete understanding of your project.
When you work with Dev Agent, you can reference URLs, files, folders, problems, terminal output, git changes, and even Salesforce sObjects directly in your conversations. This transforms how you interact with Dev Agent by providing complete context without manual copying and pasting.
Available Context Types:
Context Type | Usage | What Dev Agent Sees |
---|---|---|
File Context | Reference any file in your workspace | Complete file content, imports, and surrounding context. |
Folder Context | Reference entire directories | Folder structure and all file contents. |
Problem Context | Show all errors and warnings | Complete list with file locations and error messages. |
Terminal Context | Share recent terminal output | Complete output with formatting preserved. |
Git Context | Reference changes or commits | Complete diff, commit message, and relevant information. |
URL Context | Reference web content | Complete web page content for documentation or issues. |
sObject Context | Reference selected sObject | Select sObject from a list. |
Key benefits:
- Eliminate copy-paste: Reference content directly without manual copying.
- Preserve context: Dev Agent sees complete context including related code.
- Maintain formatting: Terminal output and error messages keep their formatting.
- Enable complex workflows: Combine multiple context types for complete understanding.
Context transforms how you interact with Dev Agent by enabling complex Salesforce development workflows. Instead of describing problems or manually copying code snippets, you can combine multiple context types to give Dev Agent a complete picture.
You can explicitly select specific files, methods, and code blocks from your Salesforce DX project.
Context Type | Description | How to Add |
---|---|---|
Files | Select one or more files from your local Salesforce DX project. | Add files using the Dev Agent section in the right-click context menu, command palette. (Dev Agent: Add File as Context), or click the @ symbol in the chat box. |
Methods | Choose individual methods within an Apex file. | Right-click inside an Apex method and choose Dev Agent: Add Method as Context, or use the command palette. |
Selected Code Blocks | Highlight and add specific sections of code. | Highlight code and right-click to add using Dev Agent: Add Selection as Context, or use the command palette. |
Imagine you're troubleshooting discount logic that spans multiple Apex classes. The implementation calculates opportunity discounts based on various business rules, but the logic isn't working as expected—some opportunities aren't receiving the correct discounts.
You might ask Dev Agent a general question: "Why isn't my discount logic working on opportunities?"
Without context, Dev Agent can offer only broad suggestions. However, to get more targeted help, you can add two Apex classes as context:
OpportunityDiscountCalculator.cls
DiscountHelper.cls
Then, you can refine your question:
"My OpportunityDiscountCalculator
and DiscountHelper
classes aren't applying the correct discounts on opportunities. Can you help me figure out what's wrong?"
With both files added as context, Dev Agent can take these actions.
Analyze and execute diagnostic actions
- Run SOQL queries to check opportunity data and discount field values.
- Execute Apex code snippets to test the discount calculation logic.
- Query your org's metadata to verify field dependencies and validation rules.
Identify and fix implementation issues
- Automatically add
System.debug()
statements to track data flow and execution paths. - Modify the code to handle null values and add proper error checking.
- Update method signatures and fix incorrect logic in method calls between classes.
Implement improvements directly
- Refactor complex methods into smaller, more maintainable helper methods.
- Add comprehensive test methods with proper assertions and test data.
- Deploy the updated classes to your development org and run the tests.
- Generate debug logs and analyze the execution results to verify the fixes.
When working with Apex classes, you can provide comprehensive context:
For LWC development, Dev Agent can take comprehensive action:
Dev Agent can immediately:
- Fix JavaScript syntax errors and update the component files.
- Generate and run Jest tests to validate component functionality.
- Deploy the corrected component to your org using Salesforce CLI.
- Create proper error handling and loading states in the component.
- Update the component's metadata configuration for proper Lightning page compatibility.
When troubleshooting integrations, Dev Agent can execute fixes:
Dev Agent can directly:
- Execute test API calls to verify endpoint connectivity and authentication.
- Update the integration code to handle new API response formats.
- Create or update Named Credentials and Connected Apps as needed.
- Generate comprehensive test classes with mock HTTP responses.
- Deploy the updated integration and run end-to-end tests to verify functionality.
Here are some best practices for using Salesforce context.
- Pin frequently referenced files or metadata for easy access.
- Use specific code blocks for targeted questions.
- Include relevant metadata for context-aware responses.
- Check the References section to verify context inclusion.
- Clear selected context when switching between different tasks.
- Combine multiple context types for comprehensive understanding.
- Reference specific files rather than describing code snippets.
- Include error context from both IDE and terminal output.
- Share recent changes when troubleshooting new issues.
- Deployment Issues: Combine file context, terminal output, and problem context.
- Test Failures: Include test class, main class, and test execution output.
- Component Development: Reference component files, metadata, and any related Apex classes.
- Integration Debugging: Include service classes, debug logs, and external documentation.
When working with Dev Agent context, be aware of these current limitations:
- Token limits affect context inclusion: Large files or extensive context may be truncated.
- Context window management: Dev Agent automatically manages context to stay within processing limits.
- File size restrictions: Very large files may not be fully included in context.
Try using context in your next conversation with Dev Agent - you'll be amazed at how much more efficient and effective your Salesforce development becomes when you can seamlessly bring in external context. The combination of multiple context types gives Dev Agent the complete picture it needs to provide targeted, accurate solutions for your Salesforce development challenges.