Print this page

Bulk API - PKChunking Header

Knowledge Article Number 000213703
Description The PK Chunking request header  is used to enable automatic primary key (PK) chunking for a bulk query job. PK chunking splits the bulk queries  into sections from the record IDs, or primary keys, of the queried records. Each chunk is processed as a separate batch that counts toward your daily batch limit, and you must download each batch’s results separately. PK chunking is supported for the following objects: Account, Campaign, CampaignMember, Case, Contact, Lead, LoginHistory, Opportunity, Task, User, and custom objects.
PKChunking header enables automatic primary key (PK) chunking for a bulk query. 
Resolution PKChunking header is added to while creating Bulk API job (not batch). Let's create a job like following (contentType is case sensitive; use "CSV"):
 
POST
Host: https://instance/services/async/33.0/job

Headers:
Content-Type: application/xml; charset=UTF-8
X-SFDC-Session: [Session ID]
Sforce-Enable-PKChunking: chunkSize=10000; (If different from default chunkSize)

Body:
<?xml version="1.0" encoding="UTF-8"?>
<jobInfo xmlns="http://www.force.com/2009/06/asyncapi/dataload">
    <operation>query</operation>
    <object>task</object>
  <contentType>CSV</contentType>
</jobInfo>

Next step is to add a batch:
 
POST
Host: https://instance/services/async/33.0/job/[Job ID]/batch

Headers:
Content-Type: text/csv; charset=UTF-8
X-SFDC-Session: [Session ID]

Body:
select id from task

This will create a batch. Keep checking the status of this batch. System will chunk the original query and create multiple batches. Once all the batches have been added, original batch status will change to "Not Processed". This batch is still kept in the job for 1) for logging purpose 2) to generate "chunked" batches. This indicates that all the batch "chunks" have been created. Once the original batch status has been changed to "Not Processed", job can be closed (we will need to explicitly close the job at this point). We can, then, query all the batches in that particular job, ignore the original batch (with "Not Processed") status and go through all batches for status/result. 
 
GET
Host: https://instance/services/async/33.0/job/[Job ID]/batch

Headers:
Content-Type: application/xml; charset=UTF-8
X-SFDC-Session: [Session ID]

Following are some links for more information about PKChunking:

 




promote demote