# How To Use a Text Field As a Reference Field

While it is best practice to store Salesforce Reference Ids in Reference Fields, there are a handful of situations where a Reference Id may be stored in a Text field.

By default, CopyStorm/Restore will use Reference Field metadata to determine whether or not a field contains a Reference Id, and which table(s) the Id may reference. In cases where Reference Ids are stored in Text fields CopyStorm/Restore can be configured to treat the field as a Reference Field, which will cause CopyStorm/Restore to:

* Take the reference information into account when determining the table restore order.
* Use CopyStorm/Restore’s Old Id to New Id mapping to ensure referential integrity when uploading field values for the Text field.

To configure CopyStorm/Restore to treat a Text field as a Reference field:

1. Create a file `[CopyStormRestore]/config/CopyForceMetadata.xml`
2. Use the following template to populate the file:

```
<CopyForceMetaData>
<!--
Treat the field Contact.TextField__c as a reference field which:
- Contains references to either the Account or Contact table.
- Uses a relationship name of MyCustomRelationship.
-->
	<FieldRule table="Contact" field="TextField__c" relatedToTable="Account,Contact" relationshipName="MyCustomRelationship"/>
</CopyForceMetaData>
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://learn.capstorm.com/copystorm-restore/reference/configuration-files/how-to-use-a-text-field-as-a-reference-field.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
