During a working session with the Quarra client, the team used an AI coding agent to build a custom Apex trigger that automatically prepends a timestamp and user initials to new entries in the Task object's Comments field. This article documents the approach, the platform limitations encountered, and the final workaround implemented.
Client: Quarra (Salesforce instance)
Related meeting: [1]
When a user adds or edits a comment in the Task Comments field, the system should automatically:
An Apex trigger was deployed on the Task object. Apex is Salesforce's lowest-level proprietary language, sitting below declarative configuration and Flow. It fires server-side on record save, making it suitable for field manipulation that can't be done through the standard UI.
The trigger logic:
- Detects when the Comments field has been modified
- Identifies the genuinely new text added above the existing content
- Stamps that new text with [date] [user initials]: prefix
- Preserves prior entries below a separator
Salesforce Lightning's standard text area component controls cursor behavior at the browser level. Apex cannot set cursor position. When a user opens the edit form, the cursor always lands at the end of the field content — meaning users must manually scroll up and create a blank line before typing.
This is a hard platform limitation; no amount of trigger refinement can override Lightning's front-end behavior.
To improve UX and reduce confusion, a custom Quick Action button labeled "Edit Comments" was added to the Task page layout. This gives users a dedicated, clearly labeled entry point for adding comments, separate from the standard inline pencil-edit icon.
Workflow for users:
1. Click Edit Comments
2. Place cursor at the top of the field
3. Type new comment, press Enter once
4. Click Save
The trigger fires on save and stamps the entry automatically.
Action item: Remove the default pencil edit icon from the Task layout to avoid confusion with the new Edit Comments button. (Owner: Mark Hope)
This feature was built entirely through iterative prompting of a Claude-based coding agent connected to the Salesforce API. Key observations:
| Layer | Language/Tool | Used For |
|---|---|---|
| UI configuration | Setup / Object Manager | Fields, layouts, page assignments |
| Declarative logic | Flow / Process Builder | Conditional automation |
| Mid-level scripting | JSForce / Force.com | API-level data access |
| Low-level code | Apex | Triggers, complex logic, field manipulation |
Apex requires Salesforce to inspect and approve code before deployment. On heavily customized instances (like Quarra's), existing customizations can conflict with new triggers and slow deployment.