Generate email drafts instantly using LWC and Model AI, helping Sales Reps save time, reduce repetitive writing, and ensure consistent, personalized communication across the sales process.
This scenario has been designed for developer who possess Intermediate skills in Lightning Web Component and Apex along with Agentforce Models API
- Reduces repetitive email drafting.
- Uses AI to generate tailored emails based on prompts.
- Stores email drafts in a custom object.
- Adds an approval layer for quality assurance.
- Makes approved emails reusable by others.
- Restricts usage and visibility through permission sets and record-level access.
🧱 Core Components
1. Lightning Web Component (LWC) UI in Utility Bar
- Available only to users with a specific permission set (
Composer_Admin). - UI:
- Prompt input
- “Generate Email” button
- “Save Draft” and “Submit for Approval” options
- Dynamically show/hide components or disable functionality if the user lacks the permission set.
2. LLM Integration
- Secure callout to Agentforce Model API
- Full error handling (timeouts, malformed prompts, bad responses).
- Optionally log callouts for auditing/debugging.
3. Custom Object: Email_Draft__c
- Fields:
Prompt__cDraft_Text__cCreated_By__c(auto-filled)Status__c(Draft,Pending Approval,Approved,Rejected)Approved_By__cUse_Case__c
- Record Visibility Control:
- By default, only visible to the creator and system admins.
- Once
Status__c = Approved, sharing rule or Apex sharing grants visibility to all users or a defined group. - Use sharing rules, criteria-based sharing, or a trigger to share approved drafts.
🔐 Security Rule:
Only users with theComposer_Adminpermission set can access and use the LWC email generator.
Non-admins cannot generate or submit drafts but may see approved drafts only if sharing is enabled.
4. Approval Flow Setup
- Triggered when draft is submitted (
Status__c = 'Pending Approval'). - Approval will be sent to user manager
- Approver reviews and updates
Status__caccordingly. - Post-approval action:
- Set
Status__c = 'Approved'. - Automatically update sharing (via Apex or Flow) to make the draft visible to others.
- Set
- Rejected → Send notification to creator, allow resubmission.
5. Sharing Approved Emails
- Displayed in another LWC or component accessible to all sales reps.
- Only
Email_Draft__crecords withStatus__c = 'Approved'are shown. - Filters prevent access to unapproved drafts unless the viewer is the creator or an admin.
Do you need help?
Are you stuck while working on this requirement? Do you want to get review of your solution? Now, you can book dedicated 1:1 with me on Lightning Web Component completely free.
GET IN TOUCH
Schedule a 1:1 Meeting with me
Also checkout this https://salesforcediaries.com/category/lightning-web-component
