Sub topic 7
Finding and reading records
This chapter covers the three standard actions that locate and read Salesforce records: Identify Record by Name, Query Records, and Get Record Details. It assumes you know the Salesforce data model (objects, fields, records), can find your way around Setup and Agentforce Builder, and know that an agent chooses actions based on topic instructions. You should also know that permission sets and profiles control what a user can see.
Why lookup actions come first
Most agent tasks start with a record. A user says "Summarize Acme" or "Update the Edge Communications opportunity." The agent has a name in plain text, but later actions need a record ID. The lookup actions close that gap, and they also let the agent read field values back to the user.
The three actions divide the work like this:
| Action | Input you give it | What it returns | Typical use |
|---|---|---|---|
| Identify Record by Name | An object and a name | The matching record, including its ID | The user names one record |
| Query Records | A description of what to find, in natural language | A set of records with selected fields | The user asks for a list or filtered set |
| Get Record Details | A record ID | Field values for that record | The user asks about one record you already identified |
The Query Records and Get Record Details actions show up in different forms depending on your org's release, so check the names in the action list in Agentforce Builder. The roles above stay the same.
Identify Record by Name
Use this action when the user refers to a single record by its name. It searches the object you point it at and returns the record that matches. The returned ID is the main output, because later actions take it as input.
Three behaviors matter in practice:
- A name can match zero, one, or several records. "Acme" could match "Acme Corp" and "Acme Industries."
- The agent should not guess when more than one record matches. Your instructions must say what to do.
- The search works on the object's name field. It does not search every text field, so a phone number or email address will not find an account.
Query Records
Query Records is for questions that return a list or depend on conditions. Examples are "Show my open opportunities closing this quarter" and "Which contacts at Acme are in California?" The agent turns the request into a query on an object. You can think of it as generating a SOQL query, which looks like this:
SELECT Name, StageName, CloseDate, Amount
FROM Opportunity
WHERE IsClosed = false AND CloseDate = THIS_QUARTER
ORDER BY CloseDate
LIMIT 10You do not write this query yourself. It shows what the action does for you. Because the agent builds the query from natural language, results depend on three things: how clearly the user asks, which fields are visible to the user, and how well your instructions describe the object.
Query Records is a poor fit for finding one named record. It can do it, but Identify Record by Name is more predictable for that job. Queries also return a limited number of rows, so do not rely on the action for exhaustive reports. Use a report or a custom action for those.
Get Record Details
Get Record Details reads the field values of one record. It needs a record ID, so it normally runs after Identify Record by Name or after Query Records. Use it when the user asks things like "What is the billing city on this account?" or "When does this opportunity close?"
It differs from the summary action, which the next chapter covers. Get Record Details returns facts as stored. A summary condenses a record into a short narrative. When the user wants a specific value, reading it is more accurate than summarizing it.
How the actions work together
A typical conversation runs the actions in sequence. The output of the first action becomes the input of the second.
The branch after the match count is the part you have to design. The actions do not decide what to do with zero or several matches. Your topic instructions do.
Writing instructions that use lookups reliably
The topic instructions should state the order of actions and the failure behavior. Here is an example for an account support topic:
Topic: Account Support
Classification description:
Handle questions about a customer's account, such as looking up an account or reading its fields.
Instructions:
1. When the user names an account, first use Identify Record by Name on the Account object. Use the returned record ID for every later step.
2. When the user asks for a specific field value of that account, use Get Record Details with the record ID. Do not answer from memory.
3. When the user asks for a list of records, such as open cases or upcoming opportunities, use Query Records.
4. If Identify Record by Name returns no match, tell the user and ask for another name.
5. If it returns more than one match, list the candidates and ask the user which one they mean. Do not pick one yourself.Each rule does a specific job. Rule 1 prevents the agent from passing a name where an ID is expected. Rule 2 stops the model from inventing field values. Rules 4 and 5 handle the branch in the diagram.
Common errors
- The agent calls Get Record Details with a name. The action needs an ID. Fix this by telling the agent to run Identify Record by Name first and reuse its output.
- The agent picks the wrong record. This happens when instructions are silent about multiple matches. Add an explicit "ask, do not guess" rule.
- A field is missing from the answer. The user may not have field-level security access to it, or the field may not be part of what the action returned. Check the field's visibility for the user's profile and permission sets before changing the agent.
- A record the user expects is not found. Sharing rules may hide it. The actions run in the context of the user, so a record the user cannot open in Salesforce is also invisible to the agent.
- Query results look incomplete. The action returns a limited set of rows. Ask for a narrower filter, or use a different tool for full exports.
- The wrong object is searched. If the user says "Acme" and the topic covers both accounts and leads, the agent has to infer the object. Name the object in your instructions.
Testing a lookup
Test with at least three inputs: a name that matches one record, a name that matches several, and a name that matches none. In the Builder's conversation preview, open the plan or action trace to confirm which action ran, what input it received, and what it returned. Then run the same test as a user with a restricted profile, and check that hidden fields and records do not appear. The chapter on testing and debugging covers this inspection in more detail.
Summary of decisions
- One named record: use Identify Record by Name.
- A list or a filtered set: use Query Records.
- Specific field values for a known record: use Get Record Details with the ID.
- Always specify the behavior for no match and for several matches.
Exercise
A user asks, "What's the annual revenue for Globex?" Your topic has all three lookup actions. Which actions should the agent run, in what order, and what should your instructions say to do if two accounts are named Globex?
Show answer
The agent should run Identify Record by Name on the Account object to get the record ID, then run Get Record Details with that ID to read the annual revenue field. If two accounts match, the instructions should tell the agent to list the candidates and ask the user which one they mean instead of choosing one. Query Records is not needed because the user asked about one named record, not a list.
Exercise
A sales rep tests the agent and gets the annual revenue for an account. A support rep asks the same question about the same account and the agent says it cannot find the value. Name two likely causes that do not involve changing the agent's instructions.
Show answer
The support rep's profile or permission sets may lack field-level security access to the annual revenue field, or sharing rules may mean the support rep cannot see that account record. The lookup actions run with the user's own access, so different users can get different results from the same agent.