Creating Salesforce Cases via REST API with file attachments and bulk operations

I managed to successfully create individual Cases through Salesforce REST API, but I’m running into some challenges with more advanced scenarios.

Specifically, I need guidance on two main areas:

  1. Bulk case creation - What’s the best approach to create multiple cases at once instead of making individual API calls?

  2. Adding file attachments - Is it possible to attach files (like Excel spreadsheets or documents) when creating cases through the API?

I’ve been working with the standard case creation endpoint, but I can’t figure out how to handle these more complex requirements. Has anyone successfully implemented either of these features? Any code examples or documentation references would be really helpful.

I’m particularly interested in understanding the payload structure needed for bulk operations and whether attachments require separate API calls or can be included in the initial case creation request.

hey there! for bulk cases you’ll want to use the composite api endpoint - way more efficent than individual calls. as for attachments, unfortunatly you cant include them directly in case creation, needs to be seperate call after case is made. check out the contentversion object for file uploads.

Been working with Salesforce REST API for about three years now and encountered similar challenges. While others mentioned Composite API, I found that for straightforward bulk case creation without complex dependencies, the standard Bulk API 2.0 actually performs better when dealing with hundreds of cases simultaneously. The setup is slightly more involved but handles larger datasets more reliably. Regarding file attachments, there’s an important detail worth noting - when using ContentVersion for file uploads, make sure to set the PathOnClient field correctly and handle the FirstPublishLocationId properly to establish the relationship with your case. One gotcha I learned the hard way is that file size limits still apply, so implement proper validation on your end before attempting uploads. Also consider the org’s storage limits when designing your attachment strategy, especially if you’re dealing with bulk operations where multiple large files could be uploaded simultaneously.

I’ve implemented both scenarios in production environments. For bulk operations, the Composite Graph API is your best bet - it allows you to create up to 500 records in a single request with better error handling than the standard Composite API. You can define dependencies between operations which is particularly useful. Regarding file attachments, the workflow requires two separate calls as mentioned. However, I recommend using the Files API (ContentDocument/ContentVersion) rather than the older Attachments API since it’s more robust and supports better file management. Create your cases first, then upload files using ContentVersion with the appropriate ContentDocumentLink to associate them with the cases. One important consideration is transaction limits - if you’re processing large volumes, implement proper retry logic and consider using bulk API v2.0 for truly large datasets exceeding REST API limits.