1

I'm extremely new to salesforce and Bulk API. I've search for a possible solution for a couple of days, but haven't had any luck.

I'm using the java examples for the bulk api load that I found here, here and here but I can't find the solution I'm looking for or I have missed something.

I have a CSV file with roughly 63 columns and roughly 1 million records. My goal is to upload this single CSV file to multiple sobjects. I'm currently able to upload to a single sobject with a CSV file that has the exact names as the sobject. I have found this link but I'm unable to find information on how to actually use this spec.csv file. Building it shouldn't be a problem. I need to break up this CSV file with 1 million records into multiple sobjects. A few columns need to go into Account and Contact and a few need to go into my custom objects as well. All in all, there are 6 sobjects this CSV file will populate. Can someone please direct me how this is possible?

Thank you in advance.

  • 2
    For this situation we have made the mapping from the original single upload object populated by the bulk API to the multiple final destination objects a separate processing step. That second step can be kicked off via an insert trigger on the original upload object or done as a complete second pass using a Batchable. But in either case you have to write Apex code that grabs the relevant fields and inserts the destination object rows including correctly setting the relationship ID values. And be aware of the governor limits involved. – Keith C Aug 24 '15 at 15:12
  • Ah.. humm.. do you have an example of this so I can better understand the process? – Humpy Aug 24 '15 at 15:26
  • I've added an example as an answer so I can format the code. – Keith C Aug 24 '15 at 16:05
1

In response to the comment thread...

Here simple example of using a trigger to transfers from the bulk API uploaded Upload__c records to Account and Contact records:

// Fields of Upload are the CSV fields
trigger OnUploadInsert on Upload__c (after insert) {
    Account[] accounts = new Account[] {};
    Contact[] contacts = new Contact[] {};
    for (Upload__c u : Trigger.new) {
        accounts.add(new Account(
                Name = u.CompanyName__c
                ));
        contacts.add(new Contact(
                FirstName = u.First__c,
                LastName = u.Last__c,
                Birthdate = u.DateOfBirth__c
                ));
    }
    insert accounts;
    for (Integer i = 0; i < accounts.size(); i++) {
        contacts[i].AccountId = accounts[i].Id;
    }
    insert contacts;
}

In a real world example relationships are not necessarily 1 to 1 and things get more complicated when you want to hook up to existing data too.

| improve this answer | |
  • Just to clarify a bit.. I would want to create a custom object and do a bulk load to that custom object. That custom object would have the same fields as the CSV file... and then I would modify the code above to send the fields to the correct objects? – Humpy Aug 24 '15 at 16:26
  • 1
    @Humpy Yes that is the pattern we have used. (There may be better ways to do this so see what other answers you get.) – Keith C Aug 24 '15 at 16:29
  • Okay, cool. Thanks for the help and clarifying that for me. – Humpy Aug 24 '15 at 16:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.