Can I manually add constraints to a column in a table synced with Salesforce?

Issue

When I set unique constraints to a column on Salesforce, it's not reflected in the database. Can I manually add it to the database, too? In addition to that, can I also add other constraints such as Not-Null constraints?

Resolution

While synced records must be unique in the database when the unique option is set in Salesforce, you can also set the constraints to the column in the database to avoid insert duplications if it is read/write mapping. Please note that Salesforce unique constraints can be either case sensitive or case insensitive while it is case sensitive in Postgres. If you want to set it as case insensitive in the database, an approach is to create a function index, for example, UPPER(column_name).

Regarding other constraints, you should not set Not-Null and Foreign Keys constraints. It will cause sync issues when reloading the mapping object. Primary Keys is already used, and you can't set it. Check and Exclusion Constraints can be added but Salesforce doesn't have such a constraint. That inconsistency may cause sync issues, and we don't recommend using these constraints.

Please note that recreating the mapping or importing the config file will remove the constraint in the database.

Ask on Stack Overflow

Engage with a community of passionate experts to get the answers you need

Ask on Stack Overflow

Heroku Support

Create a support ticket and our support experts will get back to you

Contact Heroku Support