Closed Won to Onboarding Brief
On-demand webhook trigger (Salesforce Record-Triggered Flow). Receives an optional Opportunity Id in the request payload. When oppId is provided, queries and processes only that single Opportunity (still filtering Onboarding_Brief_Generated__c = false). Falls back to the full Closed Won sweep when no oppId is passed. For each matched opp: enriches with OpportunityContactRole contacts + account email domain; gathers matched call transcripts from Avoma and Granola within the sales-cycle window (MOCK fixtures during build) matching on attendee email, account domain, or fuzzy account-name title match; calls the onboarding-brief-analyst agent (Sonnet) once per opp for qualitative extraction (goals, successCriteria, stakeholders, risks, openItems), parsed defensively with per-item concurrency 2 + versioned checkpoints; assembles an HTML (Note) and plain-text (Chatter) brief where the Deal Summary comes only from Salesforce fields; writes back a ContentNote (base64 HTML) linked via ContentDocumentLink plus a Chatter FeedItem, then PATCHes Onboarding_Brief_Generated__c=true only after both writes succeed. All counts/formatting done in code; LLM used only for step 4 extraction. Auth: SALESFORCE_BEARER_TOKEN (bearer token in Authorization header). Salesforce secrets: SF_TOKEN_URL, SF_CLIENT_ID, SF_CLIENT_SECRET.
Shared by dani · Brainfish.
Remixed 0 times on Ballet.
How it works
- Mint a Salesforce access token via OAuth client-credentials; guards against null token. — Connecting to Salesforce…
- Query Salesforce for Closed Won opps where Onboarding_Brief_Generated__c=false; paginates fully. When oppId is provided, targets only that Opportunity. — Fetching Closed Won opportunities from Salesforce…
- For each opp query OpportunityContactRole for contacts and derive domain from Account.Website. — Enriching opportunities with contacts and account details…
- Build mock Avoma/Granola call fixtures per opp and match by email, domain, or fuzzy account-name title. — Gathering matched call transcripts for each opportunity…
- Call onboarding-brief-analyst agent once per opp; defensively parse JSON; checkpoint per opp, concurrency 2. — Extracting onboarding brief insights from call transcripts…
- Assemble HTML and plain-text onboarding briefs; Deal Summary built solely from Salesforce fields. — Assembling onboarding briefs…
- PATCH each Opportunity with AvomaCSHandoffNote__c (plain-text brief, ≤32 768 chars) and Onboarding_Brief_Generated__c=true; treats HTTP 204 as success. — Writing onboarding brief back to Salesforce…
Sample output
Created by AI. Fictional demo data — not a customer run.
Remix this playbook