Contact Us

April 24, 2025

May 13, 2026 4:37 pm

Getting the Current Record Id in Agentforce Agent Script

Share with

Understanding the Issue

The issue arises when trying to access the current record id using the linked variable. The community member tried using a linked string with the source as @session.recordId, but it did not capture the current record id.

The root cause of the issue is that the linked variable does not have access to the current record id. The solution is to use a topic instruction to set the current record id and then use it as an input parameter in an action.

Solution

To solve the issue, add a topic instruction with the current record id. The instruction should be in the format: “The current record ID is @currentRecordId”. Then, add an input parameter to an action with the current record id. The input parameter should be in the format: “with accountId= @variables.currentRecordId”.

Agent Script

currentRecordId: mutable id
        description: "The Salesforce ID of the current record"
        visibility: "External"

# Topic Instruction
The current record ID is @currentRecordId

# Action
with accountId= @variables.currentRecordId

By following these steps, you should be able to access the current record id in your Agent Script.

Additional Tips

Heads up: Make sure to use the correct syntax and formatting when adding the topic instruction and input parameter.

Checklist

  • Add a topic instruction with the current record id
  • Use the correct syntax and formatting for the topic instruction
  • Add an input parameter to an action with the current record id
  • Use the correct syntax and formatting for the input parameter
  • Test the Agent Script to ensure it is working as expected
  • Check the Agent Script logs for any errors or issues

What is the syntax for the topic instruction?

The syntax for the topic instruction is: “The current record ID is @currentRecordId”

How do I add an input parameter to an action?

To add an input parameter to an action, use the format: “with accountId= @variables.currentRecordId”

What if I encounter errors or issues with the Agent Script?

If you encounter errors or issues with the Agent Script, check the logs for any errors or issues and adjust the syntax and formatting as needed.

Can I use this solution for other types of records?

Yes, you can use this solution for other types of records by adjusting the topic instruction and input parameter to match the record type.

Genetrix Technology · Salesforce Marketing Cloud Partner

Need help shipping this in production?

Genetrix builds and untangles Salesforce Marketing Cloud and Agentforce setups for teams that want it done right the first time. If anything in this post sounds familiar, talk to us before it ships.

Get in Touch with Genetrix →

Blogs for the

Business-Savvy!​

Let’s Connect

A 30 min no cost strategy session
with cloud support expert

Let’s Connect

A 30 min no cost strategy session
with cloud support expert