User-Specified Context for Dev Assistant

User-specified context in Dev Assistant helps you maintain context awareness during your interactions. This feature allows you to add specific Apex or Lightning Web Component (LWC) files, Apex methods, selected code, and local metadata to your chat sessions. By using this feature, you can get more precise and contextually relevant responses from Dev Assistant.

User-specified context enables you to:

  • Select specific files, methods, and code blocks from your Salesforce DX project to add as context.
  • Include local metadata in your queries for more context-aware responses.
  • Easily add or remove context sources.

Context set using this feature takes precedence over Retrieval-Augmented Generation (RAG).

User-specified context is a feature of Agentforce for Developers and is designed to work with the Salesforce DX project structure.

Type of ContextDescriptionHow to Add
FilesSelect one or more files from your local Salesforce DX project. You can add one file at a time.Add files as context using the Agentforce section in the right-click context menu or by opening the command palette and running Agentforce: Add File as Context. You can also click the @ symbol in the chat box to pick a file.
MethodsChoose individual methods within a file.Right-click inside an Apex method and choose Agentforce Method as Context from the Agentforce context menu, or use the command palette to run the same command. If the cursor isn’t inside the Apex method, a picker will help you select one.
Selected Code BlocksHighlight and add specific sections of code in the active editor.Highlight code and right-click to add using Agentforce: Add Selection as Context, or use the command palette. If no code is highlighted, the line where the cursor is positioned will be added as context.

Imagine you're troubleshooting a 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 the Dev Assistant a general question:

Why isn’t my discount logic working on opportunities?

Without context, Dev Assistant can only offer broad suggestions, such as checking conditional logic, reviewing field values, or confirming related record data. 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 Assistant can:

Analyze the full logic flow

  • Trace how OpportunityDiscountCalculator delegates logic to DiscountHelper.
  • Identify how fields like Amount, StageName, and Discount_Level, are used across the classes.

Detect implementation issues

  • Spot missing or incorrect logic in method calls between classes.
  • Flag potential issues like null values, incorrect filters, or misaligned business rules.

Recommend improvements

  • Suggest adding System.debug() statements to track data and execution.
  • Highlight where logic could be streamlined or refactored into helper methods.
  • Point out gaps between expected and actual behavior based on code patterns.

By providing multiple related files as context, you can enable Dev Assistant to deliver more accurate, code-specific responses.

After receiving a response, you can view the included context from the Used references dropdown. If some references are excluded due to token limits, you see a truncated list. When token limits are reached, context is prioritized in the following order:

  1. Recent chat history of the current session.
  2. Currently active, or visible text in the currently active file or method.
  3. Explicitly selected context.
  4. Context retrieved via RAG for Apex and metadata.

Here are some tips to help you make the most of user-specified context:

  • Pin frequently referenced files or metadata.
  • Use specific code blocks for targeted questions.
  • Include relevant metadata for context-aware responses.
  • Check the References section to verify context.
  • Remember to clear the selected context when switching tasks.
  • Token limits affect context inclusion.

Salesforce DX Project Structure