djangoherokudjango-modelssalesforceheroku-connect

Django heroku connect read-write primary key issue


i am using djagno-heroku-connect library,salesforce and heroku connect link below for library

https://github.com/Thermondo/django-heroku-connect


So the problem that i am facing is i have one model that is marked as read-write, so which field should i make as primary key,

I can't make sf_id as pk, because when i create one object it won't be there, as this is provided by salesforce

As suggested in docs create external_id, but this won't be present if data from salesforce is synced back to my database let's say postgres

There is one id field in postgres which is used by heroku connect and its suggested in docs on not to use that

and i am not willing to user salesforce API for this, is there any approach to do this?

Thanks in advance


Solution

  • Hey Achintya Ranjan Chaudhary!

    My name is Rust, and I am one of django-heroku-connect maintainers. I will happily try to assist you here.

    You are totally right with your notes about sf_id field — this one cannot be used as a primary key due to its nature (it will be only filled by SF and it is not possible to have an instant value there when object is created via Python/Django).

    There is no strict requirement coming from the library about primary key, explicit definition can and should be ignored, which means, Django will automatically set up default primary key field similar to:

    id = models.AutoField(primary_key=True)
    

    That way the field will be mapped with Heroku Connect system field id. This is exactly how we at Thermondo are using our library and it is totally fine, but you have to make sure you are not using this primary key in your code. Heroku Connect will not guarantee the consistency and ordering of the objects and, for example, table re-sync operation will completely change ids of the objects.

    As an extra suggestion, I'd propose to have external_uuid UUID field which will be automatically filled by Django (setting up a default on model definition) and by Salesforce (this will require custom trigger that will fill ExternalUUID__c field with generated UUID value). This will help you to have a unique system-agnostic reference id that can be used for relations or for other inter-communication operations.

    I hope, this was helpful, but please, without any doubts approach with any further questions regarding this topic!

    Best,
    Rust