Agentforce Context
Context is one of Agentforce'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 Agentforce a more complete understanding of your project.
When you work with Agentforce, 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 Agentforce by providing complete context without manual copying and pasting.
Available Context Types:
Context Type | Usage | What Agentforce 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 | Abbreviated json for selected sObject metadata. |
Key benefits:
- Eliminate copy-paste: Reference content directly without manual copying.
- Preserve context: Agentforce 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 Agentforce by enabling complex Salesforce development workflows. Instead of describing problems or manually copying code snippets, you can combine multiple context types to give Agentforce a complete picture.
You can add any selection in the editor as context. Right-click your selection and choose Agentforce: Add to Context from the context menu, 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 Agentforce a general question: "Why isn't my discount logic working on opportunities?"
Without context, Agentforce 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, Agentforce 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, Agentforce can take comprehensive action:
Agentforce 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, Agentforce can execute fixes:
Agentforce 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.
- 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 Agentforce context, be aware of these current limitations:
- Token limits affect context inclusion: Large files or extensive context may be truncated.
- Context window management: Agentforce 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 Agentforce - 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 Agentforce the complete picture it needs to provide targeted, accurate solutions for your Salesforce development challenges.