Skip to main content
Creating Many to Many Relationships from a CSV

Hello!

I created the schema below with (two) Master Detail Fields on the Junction-Object-AB pointing to both A and B. I believe the schema is sound for my application since this is a Many to Many relationship.

Schema:

Standard Object A

Custom Object B

Junction Object AB

My question is related to uploading the data via csv. The data is coming from an internal database and each record has a unique ID (unique to the table) already so I dont have to worry about pulling back the SFDC ID after upload from the success file.

Where I am stuck is - on object B, within one record/line I have multiple record ID's in one cell pointing to the data in Object A. So an example would be:

Object A - Developer Contact

-- Tom Jones - ID - 1

-- Johnny Depp - ID - 2

-- Christina Aguilera - ID - 3

Object B - Applications

-- Angry Birds - Dev ID - 1,2,3

-- Tetris - Dev ID - 2,3

So I would need to create 3 junction records for Angry Birds and 2 junction records for Tetris based on the Developers that worked on them.

QUESTIONS

How can I create the junction records if all the ID's are in one cell?

Do all the ID's have to be loaded in a custom field and it has to be created via a trigger? (If so, some help articles or specific search topics would be appreciated. I am not a developer by trade)

I will be working with about 30K records for Object A and 30K for object B so this cannot be done manually. I would appreciate any suggestions and/or pointing me to some help articles so I can work through it.

THANK YOU!!!
5 answers
  1. Mar 31, 2016, 6:46 PM
    Hi Mahesh. I am getting the following error:

    ERROR: AddOnTrigger: execution of AfterInsertcaused by: System.StringException: Invalid id: 9External entry point

    Any thoughts? Code is below. You can see my Objects are Contact, AddOn, Dev_AddOn(Junction)

    trigger AddOnTrigger on AddOn__c (after insert) {

    List<Dev_AddOn__c> aOBList = new List<Dev_AddOn__c>();

    Set<String> accIdSet = new Set<String>();

    for(AddOn__c obj: Trigger.new) {

    if(obj.ContactID_Values__c != null && obj.ContactID_Values__c != '') {

    List<String> accIdList = obj.ContactID_Values__c.split(',');

    accIdSet.addAll(accIdList);

    }

    }

    if(!accIdSet.isEmpty()) {

    Map<Id, Contact> accMap = new Map<Id, Contact>([Select Id, Name from Contact where Id IN: accIdSet]);

    for(AddOn__c obj: Trigger.new) {

    if(obj.ContactID_Values__c != null && obj.ContactID_Values__c != '') {

    List<String> accIdList = obj.ContactID_Values__c.split(',');

    for(String accId: accIdList) {

    if(accMap.get(accId) != null) {

    Contact acc = accMap.get(accId);

    Dev_AddOn__c aOB = new Dev_AddOn__c();

    aOB.Name = obj.Name+' '+acc.Name;

    aOB.AddOn__c = obj.Id;

    aOB.Contact__c = acc.Id;

    aOBList.add(aOB);

    }

    }

    }

    }

    if(!aOBList.isEmpty()) {

    insert aOBList;

    }

    }

    }

     
0/9000