Importing Attachments

Follow

There are two kinds of attachments in our system. Attachments added directly to objects, which can be added to almost all objects and the last CV & letter attached to a candidate. Importing these two are done in a diffent manner.

1 Importing normal attachments

First you need a CSV file with the external id, name of the attachment and the complete path to the file on your file system. It will look like:

ID File name Path
134234 Notes peter pan c:\files\Notes_peter_pan.doc
123685 Conversation wendy c:\files\Conv_wend.pdf
...etc...

Make an export of all the records of the type we want to relate to, containing the salesforce ID and the external ID field (cxsrec__external_id__c, cxsrec__find_always__c or another field which is marked as external ID) which hold the IDs matching with the IDs in the CSV. Make this export with the Apex Data Loader.

Open both CSV files in excel or open office and add a column to the attachment files, which is called "sf_ID"or something similar.

Use a formula in all rows with a vlookup, to fill this column with the salesforce IDs. More information about vlookup can be found at: http://blog.contextures.com/archives/2010/08/23/excel-vlookup-from-another-workbook/

Our CSV will now look like:

ID sf_ID File name Path
134234  a0C2400000057BW Notes peter pan c:\files\Notes_peter_pan.doc
123685  a0C2400000057BW Conversation wendy c:\files\Conv_wend.pdf
...etc...

Attention! Configure the Apex Dataloader to a Batch size of 1 for the import of attachments, change this back to the original value afterwards.

Attention! You need at least 1 API call in Salesforce for each file you upload, plus another 1000 for other stuff. If there are not enough, you will run into an "TotalRequests Limit Exceeded". The number of API calls can be found as described by the answer in: http://salesforce.stackexchange.com/questions/27103/when-i-load-the-developer-console-i-get-a-total-requests-limit-exceeded-error . Contact us if you need this limit increased.

Import this CSV file in the Apex Data Loader with an insert with the following mapping into the Attachment object (not the cxsAttachment__c object). This object is hidden by default, click show all fields.

CSV field name Salesforce field name
sf_ID ParentId
File name Name
Path Body

 

2 Importing last CV/letter

First you need a CSV file with the external id, name of the attachment and the complete path to the file on your file system.

Attention! Make sure only the most recent document of a certain candidate is in this CSV file! Make seperate CSV files for the CV and the Letter.

ID File name Path
134234 CV peter pan c:\files\CV_peter_pan.doc
123685 CVwendy c:\files\CV_wend.pdf
...etc...

Add a column called "type" in this CSV, holding either "CV" (all capitals) or "letter" (all lowercase)

Create a new field on the cxsAttachment__c object called "Path" of the type Text(255).

Upsert the CSV file using the mapping below in the cxsAttachment__c object. Do the upsert on the cxsrec__Find_always__c field.

CSV field name Saleforce field name
ID cxsrec__cxsCandidate__c.cxsrec__Find_always__c
File name name
path path__c
type cxsrec__type__c

Export all records from the cxsAttachment__c you have just imported, using a filter on the createddate into an CSV file. Check if you have the same amount of records.

Attention! Configure the Apex Dataloader to a Batch size of 1 for the import of attachments, change this back to the original value afterwards.

Attention! You need at least 1 API call in Salesforce for each file you upload, plus another 1000 for other stuff. If there are not enough, you will run into an "TotalRequests Limit Exceeded". The number of API calls can be found as described by the answer in: http://salesforce.stackexchange.com/questions/27103/when-i-load-the-developer-console-i-get-a-total-requests-limit-exceeded-error . Contact us if you need this limit increased.

Now import this CSV file into the Attachment (not cxsAttachment__c) object (Use show more in the apex dataloader). Using the following mapping. 

CSV field name Salesforce field name
ID ParentId
name Name
Path__c Body
Have more questions? Submit a request

Comments

Powered by Zendesk