salesforce_write_apex_trigger
Create or update Apex triggers in Salesforce to automate business logic and data validation for custom objects.
Instructions
Create or update Apex triggers in Salesforce.
Examples:
Create a new Apex trigger: { "operation": "create", "triggerName": "AccountTrigger", "objectName": "Account", "apiVersion": "58.0", "body": "trigger AccountTrigger on Account (before insert, before update) { /* implementation */ }" }
Update an existing Apex trigger: { "operation": "update", "triggerName": "AccountTrigger", "body": "trigger AccountTrigger on Account (before insert, before update, after update) { /* updated implementation */ }" }
Notes:
The operation must be either 'create' or 'update'
For 'create' operations, triggerName, objectName, and body are required
For 'update' operations, triggerName and body are required
apiVersion is optional for 'create' (defaults to the latest version)
The body must be valid Apex trigger code
The triggerName in the body must match the triggerName parameter
The objectName in the body must match the objectName parameter (for 'create')
Status information is returned after successful operations
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| operation | Yes | Whether to create a new trigger or update an existing one | |
| triggerName | Yes | Name of the Apex trigger to create or update | |
| objectName | No | Name of the Salesforce object the trigger is for (required for 'create') | |
| apiVersion | No | API version for the Apex trigger (e.g., '58.0') | |
| body | Yes | Full body of the Apex trigger |