Agentforce Context

Context is one of Agentforce's most important features, letting you bring information into your Salesforce development conversations. Instead of copying and pasting code, errors, or docs, you can reference them directly so Agentforce has the full project context. Your Salesforce development becomes more efficient and effective when you can seamlessly bring in external context. The combination of multiple context types gives Agentforce the complete picture it needs to provide targeted and accurate solutions for your Salesforce development challenges.

When you work with Agentforce, you can reference URLs, files, folders, problems, terminal output, Git changes, and even Salesforce sObjects directly in your conversations. Just click @ in the Agentforce chat interface. You can also drag and drop image files into the chat. This transforms how you interact with Agentforce by providing complete context without manual copying and pasting.

You can also upload files or images directly in chat. This is called multimodal context and is available only on Pro models. Agentforce converts image-based formats to base64 and embeds text-based files directly into the user prompt. Supported file types include image-based png, jpeg/jpg, and text-based xml, json, txt, log, md, docx, ipynb, pdf, xlsx, and csv. There's a 20 MB per file limit for text-based file formats. Image limits are 10 files per task, with a maximum total size of 15 MB across all images in the task.

Available Context Types

Context TypeUsageWhat Agentforce Sees
URL ContextReference web content.Complete web page content for documentation or issues.
Problem ContextShow all errors and warning.Complete list with file locations and error messages.
Terminal ContextShare recent terminal output.Complete output with formatting preserved.
Git ContextReference changes or commits.Complete diff, commit message, and relevant information.
Upload File or ImageReference attached file or image.Full file content or image data with relevant context. Available on Pro models.
SObject ContextReference selected SObject.Abbreviated JSON for selected SObject metadata.
Folder ContextReference entire directories.Folder structure and all file contents.
File ContextReference any files in your workspace.Complete file content, imports, and surrounding context.

Key benefits

  • Reference content directly without manual copying.
  • Agentforce sees complete context, including related code.
  • Terminal output and error messages keep their formatting.
  • 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 the full picture.

You can add any selection in the editor as a context. Right-click your selection and select 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 because some opportunities aren't receiving the correct discounts.

You 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 act.

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 dataflow 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 a 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:

  • Large files or extensive context may be truncated.
  • Agentforce automatically manages context to stay within processing limits.
  • Large files may not be fully included in context.