salesforce_update_opportunity
Salesforce write high risk
Part of the Salesforce Agent.
What it does
Updates fields on an existing Opportunity by Id (most often to advance StageName, set Amount, set CloseDate, or stamp the originating LinkedIn CampaignId for attribution). 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: record_id, fields{} (only fields to change), 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 advance a deal the client owns — move StageName, set/adjust Amount or CloseDate, or stamp the LinkedIn CampaignId (Primary Campaign Source) for revenue attribution. Always preview the diff and get explicit approval; only supplied fields change. Closing a deal (Closed Won/Lost) is high-impact — always confirm.
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
record_id | string | yes | 18-char Opportunity Id to update. |
fields | object | yes | Sparse map of ONLY the fields to change, e.g. {StageName:'Closed Won', Amount:50000, CampaignId:'701...'}. Omitted fields untouched; null clears. StageName must be an active OpportunityStage. Reject unknown fields. |
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 the before->after diff, commit only on explicit approval; never auto-update. Edit only Opportunities in the authorizing client's own org (strict per-account isolation). Any LinkedIn attribution data stamped must be the client's OWN consented data used ONLY for consented purposes — never use member data for prospecting/enrichment, append/verify member profiles, build a cross-account/unaffiliated database, or commingle across clients. Honor deletion on request; member-data retention (profile <=24h, social activity <=48h) for cached source data.
Reminder
Confirm the previewed before->after diff (especially stage/amount/close-date moves) before committing; client's own org only.
Errors
| Error class | Means | What to do | Retry |
|---|---|---|---|
TOKEN_REVOKED | Session expired/invalid (HTTP 401 INVALID_SESSION_ID). | needs_reauth — refresh once and retry; PATCH is idempotent. Else prompt reconnect. | yes |
NOT_FOUND | Opportunity Id not found / deleted / out of scope (HTTP 404 NOT_FOUND / ENTITY_IS_DELETED). | Verify the Id belongs to this org. Not retryable unchanged. | no |
VALIDATION_ERROR | Invalid value (HTTP 400 INVALID_OR_NULL_FOR_RESTRICTED_PICKLIST for a bad StageName, FIELD_INTEGRITY_EXCEPTION, FIELD_CUSTOM_VALIDATION_EXCEPTION e.g. close-reason required to win). | Surface errors[].message + fields[]; verify StageName against active stages and satisfy validation rules; re-preview. | no |
PERMISSION_DENIED | User lacks Edit on Opportunity or a field, or record not shared for edit (HTTP 403 INSUFFICIENT_ACCESS). | Surface object/field; request 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. | yes |
PREVIEW_EXPIRED | preview_id unknown/expired or fields/record_id changed since preview. | Re-run preview before committing. | no |
PLATFORM_UNAVAILABLE | Salesforce 5xx (HTTP 500/502/503). | Retry with backoff; PATCH by Id is idempotent so safe to retry. | yes |
Edge cases
- Preview (no preview_id) echoes the request and returns a preview_id; nothing is sent to Salesforce.
- Closing to Closed Won/Lost may require extra fields per org config (e.g. loss reason) — handled as validation errors to surface.
- Sparse update: only supplied fields change; pass null to clear a field.
- No-op update returns 204; report 'no change'.
- Idempotency: PATCH by Id is idempotent — re-applying the same body is safe.
- Retention/consent: any LinkedIn attribution value must be the client's own consented data, not retained beyond 24h/48h.