# Salesforce composite api cache mobile dashboard

> Composite read responses cached per user id at edge. For "salesforce composite api cache mobile dashboard", 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 React Native hit only https://realcomposer.com/v1/workspace/cache-salesforce-composite-mobile-dashboard with an rc_live_ client token. Enable 120s GET cache only when query params identify the resource.

- Canonical page: https://realcomposer.com/recipes/cache-salesforce-composite-mobile-dashboard
- Client platform: React Native
- Upstream services: Salesforce
- Category: Edge Caching & Rate Limits
- JSON version: https://realcomposer.com/recipes/cache-salesforce-composite-mobile-dashboard.json
- Install in RealComposer (free plan, pre-fills this pipeline): https://realcomposer.com/dashboard/pipelines/new?recipe=cache-salesforce-composite-mobile-dashboard&via=agent

## Problem: Uncached Salesforce spikes cost and latency

Every React Native visitor can trigger a fresh Salesforce call. Bursts exhaust per-minute quotas even when data changes slowly.

- Thundering herds after cache expiry on the origin
- Analytics skewed by client-side retry storms
- Support tickets blaming "API downtime" during spikes

## Solution steps

1. **Store upstream credentials in Secret Vault**: Add SALESFORCE_ACCESS_TOKEN to RealComposer Secret Vault. Values decrypt only inside the Cloudflare Worker that calls the upstream.

2. **Configure upstream steps and output mapping**: 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.

3. **Call from React Native**: Allowed origins on the token should list every React Native host that calls this URL.

```
const res = await fetch('https://realcomposer.com/v1/workspace/cache-salesforce-composite-mobile-dashboard', {
  headers: { Authorization: 'Bearer rc_live_your_token' }
});
```

## Pipeline config

Import this config into a RealComposer pipeline. `{{secrets.NAME}}` values are read from the encrypted Secret Vault at request time, so the client never sees them.

```json
{
  "name": "Salesforce composite api cache mobile dashboard",
  "method": "GET",
  "cacheTtlSeconds": 120,
  "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"
      }
    ]
  }
}
```

## Call the pipeline

```bash
curl -X GET "https://realcomposer.com/v1/workspace/cache-salesforce-composite-mobile-dashboard" \
  -H "Authorization: Bearer rc_live_client_token"
```

## Payload before and after

Raw upstream response:

```json
{
  "requestId": "req_cache-sa",
  "upstreamLatencyMs": 142,
  "audit": {
    "region": "edge",
    "trace": "cache-salesforce-composite-mobile-dashboard"
  },
  "payload": {
    "id": "sample_id",
    "status": "active",
    "nested": {
      "tags": [
        "demo"
      ],
      "internal": true
    },
    "unused_blob": {
      "foo": "bar",
      "bar": "baz"
    }
  }
}
```

Slimmed RealComposer response:

```json
{
  "contactId": "sample",
  "email": "sample",
  "name": "sample"
}
```

## FAQ

### Is it safe to log Salesforce responses in React Native?

Use scoped tokens where the vendor allows them on cache-salesforce-composite-mobile-dashboard. Admin keys stay {{secrets.*}} references only.

### When does edge caching apply to this recipe?

cache-salesforce-composite-mobile-dashboard: only GET requests cache (120s on caches.default). Key is workspace slug plus sorted query params, not Authorization.

### What happens if an upstream step times out?

Allowed origins on the cache-salesforce-composite-mobile-dashboard client token restrict which domains may call the edge URL.
