{
  "slug": "cache-salesforce-api-at-edge",
  "title": "How to cache salesforce api responses at edge",
  "metaDescription": "How to cache salesforce api responses at edge. Shield Salesforce with 300s GET edge cache; cache key uses query params on cache-salesforce-api-at-edge.",
  "headline": "Reduce Salesforce API daily limit usage",
  "category": "caching",
  "categoryLabel": "Edge Caching & Rate Limits",
  "urgency": 8,
  "clientPlatform": "Frontend / Web",
  "upstreamServices": [
    "Salesforce"
  ],
  "searchIntentQuery": "how to cache salesforce api responses at edge",
  "directAnswerSummary": "Cache read-heavy Contact and Account queries with short TTL. For \"how to cache salesforce api responses at edge\", store SALESFORCE_ACCESS_TOKEN in Secret Vault, call https://{{secrets.SALESFORCE_INSTANCE}}.my.salesforce.com/services/data/v68.0/sobjects/Contact/{{query.contactId}} from a Worker, and let Frontend / Web hit only https://realcomposer.com/v1/workspace/cache-salesforce-api-at-edge with an rc_live_ client token. Enable 300s GET cache only when query params identify the resource.",
  "problem": {
    "title": "Salesforce rate limits from Frontend / Web traffic",
    "explanation": "Without edge caching, identical Salesforce reads during a session still round-trip to the origin.",
    "risks": [
      "HTTP 429 responses during launch traffic",
      "Surprise SaaS overages from duplicate reads",
      "Slower repeat views than necessary"
    ]
  },
  "solutionSteps": [
    {
      "stepNumber": 1,
      "title": "Add vault secrets for this pipeline",
      "description": "Create SALESFORCE_ACCESS_TOKEN vault entries, then bind them to this pipeline step headers with {{secrets.NAME}} placeholders."
    },
    {
      "stepNumber": 2,
      "title": "Set headers, mapping, and cache TTL",
      "description": "Configure headersTemplate to inject vault secrets, target https://{{secrets.SALESFORCE_INSTANCE}}.my.salesforce.com/services/data/v68.0/sobjects/Contact/{{query.contactId}}, and Add output mapping fields that mirror the JSON contract your screen already expects."
    },
    {
      "stepNumber": 3,
      "title": "Call from Frontend / Web",
      "description": "Call https://realcomposer.com/v1/workspace/cache-salesforce-api-at-edge with a restricted rc_live_ client token. Frontend / Web never sends upstream secrets.",
      "codeSnippet": "const res = await fetch('https://realcomposer.com/v1/workspace/cache-salesforce-api-at-edge', {\n  headers: { Authorization: 'Bearer rc_live_your_token' }\n});"
    }
  ],
  "pipelineConfig": {
    "name": "How to cache salesforce api responses at edge",
    "method": "GET",
    "cacheTtlSeconds": 300,
    "authMode": "client_token",
    "steps": [
      {
        "stepKey": "salesforce",
        "upstreamUrlTemplate": "https://{{secrets.SALESFORCE_INSTANCE}}.my.salesforce.com/services/data/v68.0/sobjects/Contact/{{query.contactId}}",
        "httpMethod": "GET",
        "headersTemplate": {
          "Authorization": "Bearer {{secrets.SALESFORCE_ACCESS_TOKEN}}"
        },
        "timeoutMs": 3000
      }
    ],
    "outputMapping": {
      "version": 1,
      "fields": [
        {
          "targetPath": "contactId",
          "sourcePath": "Id",
          "type": "string",
          "sourceStep": "salesforce"
        },
        {
          "targetPath": "email",
          "sourcePath": "Email",
          "type": "string",
          "sourceStep": "salesforce"
        },
        {
          "targetPath": "name",
          "sourcePath": "Name",
          "type": "string",
          "sourceStep": "salesforce"
        }
      ]
    }
  },
  "sampleBloatedInput": {
    "requestId": "req_cache-sa",
    "upstreamLatencyMs": 142,
    "audit": {
      "region": "edge",
      "trace": "cache-salesforce-api-at-edge"
    },
    "payload": {
      "id": "sample_id",
      "status": "active",
      "nested": {
        "tags": [
          "demo"
        ],
        "internal": true
      },
      "unused_blob": {
        "foo": "bar",
        "bar": "baz"
      }
    }
  },
  "sampleSlimmedOutput": {
    "contactId": "sample",
    "email": "sample",
    "name": "sample"
  },
  "curlSnippet": "curl -X GET \"https://realcomposer.com/v1/workspace/cache-salesforce-api-at-edge\" \\\n  -H \"Authorization: Bearer rc_live_client_token\"",
  "faqs": [
    {
      "question": "Can Frontend / Web call Salesforce without holding the production key?",
      "answer": "Point Frontend / Web at /recipes/cache-salesforce-api-at-edge edge URL. RealComposer answers OPTIONS with Access-Control headers for allowed origins."
    },
    {
      "question": "Does POST traffic get cached?",
      "answer": "cache-salesforce-api-at-edge POST steps bypass caches.default even if cacheTtlSeconds is set in the dashboard."
    },
    {
      "question": "How do I rotate upstream credentials?",
      "answer": "Rotate vault secrets for cache-salesforce-api-at-edge anytime; clients keep the same rc_live_ token."
    }
  ],
  "relatedRecipeSlugs": [
    "cache-rest-api-without-redis",
    "avoid-third-party-api-rate-limits"
  ],
  "updatedAt": "2026-11-20",
  "links": {
    "page": "https://realcomposer.com/recipes/cache-salesforce-api-at-edge",
    "markdown": "https://realcomposer.com/recipes/cache-salesforce-api-at-edge.md",
    "json": "https://realcomposer.com/recipes/cache-salesforce-api-at-edge.json",
    "install": "https://realcomposer.com/dashboard/pipelines/new?recipe=cache-salesforce-api-at-edge&via=agent"
  }
}