Skip to main content

Code reviews rule: Hardcoded IDs in flow

Written by David Martin
Updated this week

Hardcoded IDs in flow

Why is this an issue?

Salesforce record IDs are unique to each org. An ID that references a record in your development sandbox will not point to the same record in production or another sandbox. Flows containing hardcoded IDs will fail or behave unexpectedly when deployed to a different environment.

This commonly affects:

  • References to specific users or queues for assignment

  • Record type IDs in decision elements

  • Custom metadata or custom setting record IDs

  • Profile or permission set IDs

Examples

Example of incorrect configuration: A flow assignment element uses a hardcoded queue ID.

<assignments>
<name>Assign_to_Support_Queue</name>
<assignmentItems>
<assignToReference>recordVar.OwnerId</assignToReference>
<operator>Assign</operator>
<value>
<stringValue>00G5f000004XYZaABC</stringValue>
</value>
</assignmentItems>
</assignments>

Example of correct configuration: Use a Get Records element to query the queue by its DeveloperName, then reference the retrieved ID.

<recordLookups>
<name>Get_Support_Queue</name>
<object>Group</object>
<filters>
<field>DeveloperName</field>
<operator>EqualTo</operator>
<value><stringValue>Support_Queue</stringValue></value>
</filters>
<filters>
<field>Type</field>
<operator>EqualTo</operator>
<value><stringValue>Queue</stringValue></value>
</filters>
<outputReference>supportQueueVar</outputReference>
</recordLookups>

<assignments>
<name>Assign_to_Support_Queue</name>
<assignmentItems>
<assignToReference>recordVar.OwnerId</assignToReference>
<operator>Assign</operator>
<value>
<elementReference>supportQueueVar.Id</elementReference>
</value>
</assignmentItems>
</assignments>

How can I fix violations?

Replace hardcoded IDs with dynamic lookups:

  1. Query by DeveloperName: For queues, record types, and groups, use a Get Records element to query by DeveloperName or Name, which remain consistent across environments.

  2. Use custom metadata types: Store environment-specific IDs in custom metadata records that can be configured per environment.

  3. Use custom settings: For values that vary between orgs, use hierarchy or list custom settings.

When should I disable this rule?

You may dismiss specific violations when:

  • The ID references a standard Salesforce object that has the same ID across all orgs (rare).

  • The flow is exclusively for a single org with no plans for deployment elsewhere.

Resources

Did this answer your question?