Skip Navigation
Show nav
Heroku Dev Center
  • Get Started
  • Documentation
  • Changelog
  • Search
  • Get Started
    • Node.js
    • Ruby on Rails
    • Ruby
    • Python
    • Java
    • PHP
    • Go
    • Scala
    • Clojure
  • Documentation
  • Changelog
  • More
    Additional Resources
    • Home
    • Elements
    • Products
    • Pricing
    • Careers
    • Help
    • Status
    • Events
    • Podcasts
    • Compliance Center
    Heroku Blog

    Heroku Blog

    Find out what's new with Heroku on our blog.

    Visit Blog
  • Log inorSign up
View categories

Categories

  • Heroku Architecture
    • Dynos (app containers)
    • Stacks (operating system images)
    • Networking & DNS
    • Platform Policies
    • Platform Principles
  • Command Line
  • Deployment
    • Deploying with Git
    • Deploying with Docker
    • Deployment Integrations
  • Continuous Delivery
    • Continuous Integration
  • Language Support
    • Node.js
    • Ruby
      • Working with Bundler
      • Rails Support
    • Python
      • Background Jobs in Python
      • Working with Django
    • Java
      • Working with Maven
      • Java Database Operations
      • Working with Spring Boot
      • Java Advanced Topics
    • PHP
    • Go
      • Go Dependency Management
    • Scala
    • Clojure
  • Databases & Data Management
    • Heroku Postgres
      • Postgres Basics
      • Postgres Getting Started
      • Postgres Performance
      • Postgres Data Transfer & Preservation
      • Postgres Availability
      • Postgres Special Topics
    • Heroku Data For Redis
    • Apache Kafka on Heroku
    • Other Data Stores
  • Monitoring & Metrics
    • Logging
  • App Performance
  • Add-ons
    • All Add-ons
  • Collaboration
  • Security
    • App Security
    • Identities & Authentication
    • Compliance
  • Heroku Enterprise
    • Private Spaces
      • Infrastructure Networking
    • Enterprise Accounts
    • Enterprise Teams
    • Heroku Connect (Salesforce sync)
      • Heroku Connect Administration
      • Heroku Connect Reference
      • Heroku Connect Troubleshooting
    • Single Sign-on (SSO)
  • Patterns & Best Practices
  • Extending Heroku
    • Platform API
    • App Webhooks
    • Heroku Labs
    • Building Add-ons
      • Add-on Development Tasks
      • Add-on APIs
      • Add-on Guidelines & Requirements
    • Building CLI Plugins
    • Developing Buildpacks
    • Dev Center
  • Accounts & Billing
  • Troubleshooting & Support
  • Integrating with Salesforce
  • Heroku Enterprise
  • Heroku Connect (Salesforce sync)
  • Heroku Connect Troubleshooting
  • Heroku Connect Duplicate Record Issues

Heroku Connect Duplicate Record Issues

English — 日本語に切り替える

Last updated December 01, 2022

Table of Contents

  • Scenario
  • Prevent Duplicates By Ensuring Uniqueness
  • Re-inserted Records

Heroku Connect uses separate threads for reading and writing. It’s possible to create duplicate records when a read-write mapping doesn’t have a unique identifier. This article describes this situation and how to prevent it.

Scenario

A duplicate record gets created in this scenario:

  1. Heroku Connect writes a new record to Salesforce.
  2. Another thread starts to synchronize the record back to Postgres, before the writing thread writes the new Salesforce ID (sfid) back to Postgres.
  3. When synchronizing changes from Salesforce, Heroku Connect tries to match records by their Salesforce ID. Since it’s unavailable in this example, it falls back to using the unique external identifier for matching. If both sfid and the unique external identifier aren’t available, Connect creates a new, duplicate record in Postgres. The original record remains without its sfid set.

Prevent Duplicates By Ensuring Uniqueness

Add a custom field to your object in Salesforce and configure it as the unique identifier. This identifier prevents the creation of duplicate records. Additionally, you can also reliably reference a newly inserted row from a foreign table using the configured unique external ID.

Treat the unique identifier as an alias for a Salesforce ID. Never change or reuse them and choose a unique mechanism for generating them.

Don’t use Postgres integer sequences as they aren’t guaranteed to be unique. Don’t use the ID field in the Heroku Connect database as the unique identifier. These numbers can reset when importing your configuration into a new database or on reloading a table.

Avoid using auto-incrementing fields for unique identifiers.

Populate the unique identifier field with a unique value, such as a globally or universal unique ID (GUID or UUID) when you first INSERT the record. This strategy ensures the uniqueness of newly created records in Postgres, as well as establish relationships between objects. It’s recommended to use random UUIDs, which can be generated using gen_random_uuid().

Using gen_random_uuid() requires enabling the pgcrypto extension (CREATE EXTENSION IF NOT EXISTS pgcrypto;).

Re-inserted Records

Even when using unique identifiers, it’s possible to create duplicate records if you delete records in Salesforce shortly after syncing them via Heroku Connect. While this situation is rare, it’s not recommended to delete records in Salesforce shortly after syncing via Heroku Connect. Wait at least 10 minutes before deleting. See Re-inserted Records for more info.

Keep reading

  • Heroku Connect Troubleshooting

Feedback

Log in to submit feedback.

Heroku Connect Write Errors Heroku Connect Log Messages and Common Errors

Information & Support

  • Getting Started
  • Documentation
  • Changelog
  • Compliance Center
  • Training & Education
  • Blog
  • Podcasts
  • Support Channels
  • Status

Language Reference

  • Node.js
  • Ruby
  • Java
  • PHP
  • Python
  • Go
  • Scala
  • Clojure

Other Resources

  • Careers
  • Elements
  • Products
  • Pricing

Subscribe to our monthly newsletter

Your email address:

  • RSS
    • Dev Center Articles
    • Dev Center Changelog
    • Heroku Blog
    • Heroku News Blog
    • Heroku Engineering Blog
  • Heroku Podcasts
  • Twitter
    • Dev Center Articles
    • Dev Center Changelog
    • Heroku
    • Heroku Status
  • Facebook
  • Instagram
  • Github
  • LinkedIn
  • YouTube
Heroku is acompany

 © Salesforce.com

  • heroku.com
  • Terms of Service
  • Privacy
  • Cookies
  • Cookie Preferences