salesforce_add_campaign_member
Salesforce write medium risk
Part of the Salesforce Agent.
What it does
Attributes a Lead or Contact to a Salesforce Campaign by creating a CampaignMember (the junction that links a person to a campaign and records their response Status) — this is how a LinkedIn campaign's leads/contacts get tied to the mirrored Salesforce Campaign for influence/ROI reporting. Two-phase write (Scalix guardrail, ADR-028/029): the first call (no preview_id) echoes the exact payload as the preview and returns a preview_id WITHOUT calling Salesforce - no dedupe, diff or picklist validation happens at preview; re-call with that preview_id and identical arguments to COMMIT: the request executes, Salesforce's response is returned, and an immutable audit row is written (single-use token, 30 min; a changed, forged or replayed token fails closed). Key inputs: campaign_id, exactly one of lead_id/contact_id, status, preview_id. Returns {success:true,data:{applied,result}} where result is Salesforce's response (e.g. {id,success,errors} on create; empty on a 204 PATCH).
When to use it
Use to attribute a client's own lead/contact to the Salesforce Campaign that mirrors a LinkedIn campaign, so LinkedIn-sourced demand shows up in campaign influence and ROI reporting. Preview to confirm the campaign, that the person isn't already a member, and that Status is valid for the campaign; require explicit approval. This is the core LinkedIn->Salesforce attribution write.
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
campaign_id | string | yes | 18-char Campaign Id (the Salesforce Campaign mirroring the LinkedIn campaign). |
lead_id | string | no | 18-char Lead Id to attribute. Supply EXACTLY ONE of lead_id or contact_id (CampaignMember is polymorphic). |
contact_id | string | no | 18-char Contact Id to attribute. Supply EXACTLY ONE of lead_id or contact_id. |
status | string | no | Member response Status; must be a CampaignMemberStatus defined for this campaign (e.g. 'Sent','Responded'). Omit to use the campaign's default member status. |
preview_id | string | no | Omit it to preview: nothing is applied, and the call returns a preview_id bound to this exact request. Pass it only after the user approves that preview in a later message, with the same arguments (leave out validate_only, and add any confirmation flag the preview names). Single-use, expires in 30 minutes; changed arguments need a fresh preview. |
Safeguards
A change in two steps. The first call previews and changes nothing; Claude shows you the preview and applies it only after you approve, within 30 minutes and with the same arguments. Every applied change goes to the audit log. How changes are approved.
Policy
Two-phase: preview (validate ids/status, dedupe) then commit only on explicit approval; never auto-attribute. Strict per-account isolation — attribute only within the authorizing client's own org. The member being attributed must be the client's OWN consented lead/contact used ONLY for consented purposes — never use member data for prospecting/enrichment, append/verify member profiles, build a cross-account/unaffiliated database, or commingle leads across clients. Honor deletion on request; member-data retention (profile <=24h, social activity <=48h) applies to cached LinkedIn source data.
Reminder
Exactly one of lead_id/contact_id, a valid campaign Status, dedupe first (one membership per person per campaign), commit on approval; client's own consented data only.
Errors
| Error class | Means | What to do | Retry |
|---|---|---|---|
TOKEN_REVOKED | Session expired/invalid (HTTP 401 INVALID_SESSION_ID). | needs_reauth — refresh once; on retry, dedupe-query first since POST is non-idempotent. Else prompt reconnect. | yes |
VALIDATION_ERROR | Both or neither of LeadId/ContactId supplied, or Status is not a valid CampaignMemberStatus for the campaign (HTTP 400 INVALID_STATUS / FIELD_INTEGRITY_EXCEPTION), or a required field missing. | Surface the exact message; ensure exactly one of lead_id/contact_id and a campaign-valid Status; re-preview. | no |
CONFLICT | The Lead/Contact is already a member of this campaign (HTTP 400 DUPLICATE_VALUE on the CampaignMember unique key) or preview dedupe matched. | Return the existing CampaignMember Id (treat as idempotent success); optionally update its Status. Do not create a second membership. | no |
NOT_FOUND | CampaignId, LeadId, or ContactId not found / out of scope (HTTP 400 INVALID_CROSS_REFERENCE_KEY / 404). | Verify the Ids belong to this org; fix and re-preview. | no |
PERMISSION_DENIED | User lacks Marketing User / Edit on Campaign or Create on CampaignMember (HTTP 403 INSUFFICIENT_ACCESS). | Request the Marketing User flag + access; not retryable as-is. | no |
RATE_LIMITED | API limit exceeded (HTTP 403 REQUEST_LIMIT_EXCEEDED or 503 Retry-After). | Backoff, honor Retry-After, report quota; do not blind-retry a POST. | yes |
PREVIEW_EXPIRED | preview_id unknown/expired or inputs changed since preview. | Re-run preview before committing. | no |
PLATFORM_UNAVAILABLE | Salesforce 5xx (HTTP 500/502/503). | Retry with backoff after re-querying the dedupe SOQL to confirm no membership was created. | yes |
Edge cases
- Preview (no preview_id) echoes the request and returns a preview_id; nothing is sent to Salesforce.
- Polymorphic: exactly one of LeadId/ContactId — both or neither is rejected.
- Uniqueness: a Lead/Contact can be a member of a given campaign only once — a re-add returns/uses the existing membership (idempotent attribution).
- Status must be one of the campaign's configured CampaignMemberStatus values, not a free-text string.
- Converting a Lead later carries its campaign memberships to the resulting Contact — avoid double-attribution.
- Idempotent upsert behavior: surface the existing CampaignMember Id on duplicate rather than erroring out.
- Retention/consent: the attributed person must be the client's own consented lead/contact; do not retain LinkedIn source caches beyond 24h/48h.