Back to Salesforce Service Cloud in Google Sheets
SheetXAI logo
Salesforce Service Cloud logo
Salesforce Service Cloud · Google Sheets Guide

Chain Case Creation and CaseComment Linking in One Salesforce Composite Request From a Google Sheet

2026-05-14
5 min read

The Scenario

You are building the middleware integration. The spec says: for each inbound support event, create a Salesforce Case and immediately attach an initial CaseComment with the raw event payload. Two operations, one logical unit, one sheet row. The Salesforce composite request API supports chaining — you can reference the new Case ID in the CaseComment creation using the referenceId syntax — but building that payload by hand is the part that takes four times as long as everything else.

You have a Google Sheet: Subject in column A, Description in column B, initial comment text in column C. Ten rows to test with before you write it into the production flow.

The bad version:

  • Make a POST to the Cases endpoint, capture the returned Case ID from the JSON response.
  • Manually build the CaseComment payload with that Case ID in the ParentId field.
  • Make a second POST to the CaseComments endpoint.
  • Repeat for the remaining 9 rows, tracking which Case ID goes with which CaseComment across 20 separate API calls.

The composite request syntax was designed to eliminate exactly this. But the referenceId chaining is the kind of API detail that costs an afternoon to debug the first time you write it wrong.

The Easy Way: One Prompt in SheetXAI

SheetXAI is an AI agent inside your Google Sheet. It reads your Subject, Description, and comment text, builds the composite request payload with correct referenceId chaining, and executes the paired creation for each row.

For each row in this sheet, use a Salesforce composite request to create a Case (Subject from column A, Description from column B) and then create a CaseComment referencing the new Case ID using the referenceId syntax — write the Case ID and CaseComment ID into columns D and E

What You Get

  • One composite request per row, containing a Case creation followed immediately by a CaseComment creation that references the new Case ID via the referenceId chain.
  • The generated CaseId written into column D and the CaseCommentId into column E for each successful row.
  • Rows where either subrequest fails get error notes in columns D and E so you can see which step broke and why.
  • The referenceId linking handled correctly — you don't have to build the payload structure yourself.

What If the Data Is Not Quite Ready

The comment text in column C is too long for a single CaseComment body

Salesforce CaseComment body has a character limit. Long event payloads will fail.

For each row, if the text in column C exceeds 4000 characters, truncate it to 4000 characters before creating the CaseComment — note in column F when truncation occurred

You need to create a linked Task instead of a CaseComment

The spec changed. Now the chain is: create Case, then create a Task linked to the Case.

Chain two Salesforce operations per row in my sheet: first create a Case using Subject (A) and Description (B), then create a linked Task with Subject set to Follow-up and WhatId set to the new Case ID using the referenceId syntax — write Case ID and Task ID into columns D and E

Some rows already have Case IDs — only the CaseComment needs to be created

A partial run already created cases for rows 1 through 5. Column D has those IDs.

For rows where column D already has a Case ID, skip Case creation and only create a CaseComment for that Case ID using the text in column C — write the CaseCommentId into column E

Full chain with truncation, partial-run detection, and error logging

Handle existing Case IDs, truncate long comment bodies, create the linked CaseComment, and log all results.

For each row: if column D has a Salesforce Case ID, skip Case creation and create only a CaseComment referencing that ID. If column D is blank, create the Case (Subject A, Description B) and then create the linked CaseComment. Truncate column C to 4000 characters if needed, note truncation in column F, and write the Case ID and CaseComment ID (or errors) into columns D and E.

One prompt handles the branching logic and the chaining in a single pass.

Try It

Get the 7-day free trial of SheetXAI and open your integration test sheet, then ask SheetXAI to run the chained composite requests. For related reading, see the hub overview or the spoke on composite batch requests for handling multiple independent updates in a single API round trip.

Stop memorizing formulas.
Tell your spreadsheet what to do.

Join 4,000+ professionals saving hours every week with SheetXAI.

Learn more