| Warning Always back up your data before performing any data operation. See Export Backup Data from Salesforce or Export Data for more details. It is recommended to run a test with a small subset of records to ensure the operation was successful through manually opening and verifying that the corresponding records are correct in Salesforce. |
The first row (header row) in a CSV file lists the field names for the object that you're processing. Each subsequent row corresponds to a record in Salesforce. A record consists of a series of fields that are delimited by commas. A CSV file can contain multiple records and is referred to as a batch.
All records in a CSV file must be for the same object. You specify this object in the job associated with the batch. All batches associated with a job must contain records for the same object.
Processing CSV files with the Bulk API:
Many objects in Salesforce are related to other objects. For example, Account is a parent of Contact. You can add a reference to a related object in a CSV file by representing the relationship in a column header.
When you're processing records in the Bulk API, you use the RelationshipName.IndexedFieldName syntax in a CSV column header to describe the relationship between an object and its parent, where RelationshipName is the relationship name of the field andIndexedFieldName is the indexed field name that uniquely identifies the parent record. Use the describeSObjects() call in the SOAP-based SOAP API to get the relationshipName property value for a field.
Some objects have relationships to themselves. For example, the 'Reports To' field for a contact is a reference to another contact. If you're inserting a contact, you could use a ReportsTo.Email column header to indicate that you're using a contact's Email field to uniquely identify the Reports To field for a contact.
The ReportsTo portion of the column header is the relationshipName property value for the Reports To field.
The following CSV file uses a relationship:
1 FirstName,LastName,ReportsTo.Email 2 Tom,Jones,buyer@salesforcesample.com
Notes:
true. Custom objects use custom fields to track relationships between objects. Use the relationship name, which ends in __r(underscore-underscore-r), to represent a relationship between two custom objects. You can add a reference to a related object by representing the relationship in a column header.
If the child object has a custom field with an API Name of Mother_Of_Child__c that points to a parent custom object and the parent object has a field with an API Name of External_ID__c, use the column header Mother_Of_Child__r.External_ID__c to indicate that you're using the parent object's External ID field to uniquely identify the Mother Of Child field. To use a relationship name in a column header, replace the __c in the child object's custom field with __r.
The following CSV file uses a relationship:
1 Name,Mother_Of_Child__r.External_ID__c 2 CustomObject1,123456For more information review Introduction to SOQL and SOSL.
A polymorphic field can refer to more than one type of object as a parent. For example, either a Contact or a Lead can be the parent of a task. In other words, the WhoId field of a task can contain the ID of either a Contact or a Lead.
Since a polymorphic field is more flexible, the syntax for the column header has an extra element to define the type of the parent object. The syntax is ObjectType:RelationshipName.IndexedFieldName.
The following sample includes two reference fields:
Who. It refers to a Lead and the indexed Email field uniquely identifies the parent record.Owner. It refers to a User and the indexed Id field uniquely identifies the parent record.1 Subject,Priority,Status,Lead:Who.Email,OwnerId 2 Test Bulk API polymorphic reference field,Normal,NotStarted,lead@salesforcesample.com,005D0000001AXYz
Valid CSV Record Rows
The ObjectType: portion of a field column header is only required for a polymorphic field. You get an error if you omit this syntax for a polymorphic field. You also get an error if you include this syntax for a field that isn’t polymorphic.
The Bulk API uses a strict format for field values to optimize processing for large sets of data. Remember the following when generating CSV files that contain Salesforce records:
The following CSV sample includes two records for the Contact object. Each record contains six fields. You can include any field for an object that you're processing. If you use this file to update existing accounts, any fields that aren't defined in the CSV file are ignored during the update.
You must include all required fields when you create a record.
1 FirstName,LastName,Title,ReportsTo.Email,Birthdate,Description 2 Tom,Jones,Senior Director,buyer@salesforcesample.com,1940-06-07Z,"Self-described as ""the top"" branding guru on the West Coast" 3 Ian,Dury,Chief Imagineer,cto@salesforcesample.com,,"World-renowned expert in fuzzy logic design. 4 Influential in technology purchases."
Note: The Description field for the last record includes a line break, so the field value is enclosed in double-quotes.
When you insert, delete, or update files using the Apex Data Loader, use the Mapping Dialog window to associate Salesforce fields with the columns of your CSV file.
To import data from CSV files that don’t meet these rules, map the data fields in the CSV file to the Salesforce data fields, and review Mapping Data Fields.
See Also
000381876

We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.