salesforce_create_opportunity
Salesforce write high risk
Part of the Salesforce Agent.
What it does
Creates a new Opportunity (a revenue deal tied to an Account). 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). This is the anchor object for LinkedIn revenue attribution: create the deal here, then use salesforce_add_campaign_member to attribute the originating LinkedIn campaign and salesforce_update_opportunity to advance the stage. Key inputs: fields{} (Name, StageName, CloseDate required; AccountId, Amount, LeadSource, CampaignId (primary campaign source), OwnerId, custom __c), 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 open a revenue deal so LinkedIn-sourced demand can be tracked to pipeline/closed-won. Set CampaignId to the originating LinkedIn campaign (Primary Campaign Source) for attribution, or add it afterward via salesforce_add_campaign_member. Preview to validate the stage and required fields; require explicit approval. Do not create speculative deals or use non-client campaign data.
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
fields | object | yes | Opportunity field map. REQUIRED: Name (string), StageName (active OpportunityStage value), CloseDate (YYYY-MM-DD). Common: AccountId, Amount (number), LeadSource, CampaignId (sets the Primary Campaign Source for attribution), OwnerId, Type, plus custom __c. 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 (validate Name/StageName/CloseDate + AccountId) then commit only on explicit approval; never auto-create. Strict per-account isolation — create deals only in the authorizing client's own org. When attributing LinkedIn campaigns, use only the client's OWN campaign/lead data 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) applies to cached source data.
Reminder
Confirm Name, an active StageName, CloseDate, and AccountId in preview, then commit one Opportunity to this client's org only.
Errors
| Error class | Means | What to do | Retry |
|---|---|---|---|
TOKEN_REVOKED | Session expired/invalid (HTTP 401 INVALID_SESSION_ID). | needs_reauth — refresh once; only retry the POST if no Id was returned. Else prompt reconnect. | yes |
VALIDATION_ERROR | Missing/invalid field (HTTP 400 REQUIRED_FIELD_MISSING for Name/StageName/CloseDate, INVALID_OR_NULL_FOR_RESTRICTED_PICKLIST for a bad stage, FIELD_INTEGRITY_EXCEPTION for a malformed CloseDate, FIELD_CUSTOM_VALIDATION_EXCEPTION). | Surface errors[].message + fields[]; verify StageName against active OpportunityStage and CloseDate format; re-preview. | no |
NOT_FOUND | Referenced AccountId or CampaignId does not exist / out of scope (HTTP 400 INVALID_CROSS_REFERENCE_KEY). | Verify the Ids belong to this org; fix and re-preview. | no |
PERMISSION_DENIED | User lacks Create on Opportunity or a field (HTTP 403 INSUFFICIENT_ACCESS). | 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; do not blind-retry a POST. | yes |
PREVIEW_EXPIRED | preview_id unknown/expired or fields changed since preview. | Re-run preview before committing. | no |
PLATFORM_UNAVAILABLE | Salesforce 5xx (HTTP 500/502/503). | Retry with backoff after re-querying by Name+AccountId to confirm the Opportunity was not already created. | yes |
Edge cases
- Preview (no preview_id) echoes the request and returns a preview_id; nothing is sent to Salesforce.
- CloseDate must be a valid date (YYYY-MM-DD); a past date is allowed by the API but may trip a validation rule.
- StageName drives Probability/Forecast category via the org's stage config — using an inactive stage is rejected.
- Setting CampaignId on create stamps the Primary Campaign Source (key LinkedIn attribution field).
- Idempotency: plain create is not idempotent; on ambiguous 5xx re-query before retry to avoid duplicate deals.
- Retention/consent: any LinkedIn campaign/lead data used must be the client's own consented data.