agentleFS
animuscrmsfdcanimuscrmsfdc/salesforce-vibe-coding/.claude/skills/salesforce-developer-apex/SKILL.md

salesforce-developer-apex

Skill0 starsChanged 6 months agoMITView on GitHub

Apex development skills for animuscrm — triggers (static switch-based handler pattern), classes, platform event publishing, and security enforcement.

The file

Show its rules and text

We split this skill into the rules it gives an agent

21 rules. About 0 are common, 6 are distinctive, and 15 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈6

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 15

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    No business logic in the trigger body

    line 19
  2. Distinctive:

    No base class required

    line 20
  3. Distinctive:

    One trigger per object: If a trigger already exists for the object, extend the existing handler class — do not create a second trigger.

    line 44
  4. Very specific:

    Check force-app/main/default/triggers/ — warn and stop if a trigger for this object already exists

    line 49
  5. Very specific:

    Use switch on Trigger.operationType with only the required events

    line 51
  6. Distinctive:

    No logic in the trigger body

    line 53
  7. Very specific:

    Create force-app/main/default/classes/<ClassName>.cls with correct template

    line 91
  8. Very specific:

    Create force-app/main/default/classes/<ClassName>.cls-meta.xml (apiVersion: 66.0, status: Active)

    line 92
  9. Distinctive:

    Use this pattern whenever Apex needs to publish a Platform Event — from a trigger handler, service class, or batch job.

    line 104
  10. Very specific:

    Always use EventBus.publish() — never use insert for platform events

    line 107
  11. Very specific:

    Always check Database.SaveResult after publishing — a publish can fail silently without the check

    line 108
  12. Very specific:

    Use try/catch to handle unexpected exceptions and log them

    line 109
  13. Very specific:

    Create the mapping list: for each source record, instantiate the __e SObject and assign fields explicitly

    line 163
  14. Very specific:

    Call EventBus.publish(eventList) and capture the List<Database.SaveResult>

    line 164
  15. Very specific:

    Never put EventBus.publish() inside a loop — always bulk-collect events first, publish once

    line 167
  16. Distinctive:

    Read the target Apex class in full

    line 186
  17. Very specific:

    Add WITH SECURITY_ENFORCED to the query, OR

    line 188
  18. Very specific:

    Use Security.stripInaccessible(AccessType.READABLE, results) before returning

    line 189
  19. Very specific:

    Add Schema.sObjectType.<Object>.isCreateable() before insert/upsert

    line 191
  20. Very specific:

    Add Schema.sObjectType.<Object>.isUpdateable() before update/upsert

    line 192
  21. Very specific:

    Add Schema.sObjectType.<Object>.isDeletable() before delete

    line 193

≈ “Common” is an estimate: at least 1 in 5 of the 372,429 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Salesforce Developer Apex Skill — animuscrm

Covers Apex trigger development, class structure, and security enforcement patterns.


Trigger Pattern — animuscrm Standard

This project uses a static switch-based trigger handler pattern. All existing triggers follow this convention — new triggers MUST follow the same pattern for consistency.

The pattern:

  • Trigger body contains only a switch on Trigger.operationType block
  • Each when branch calls a static method on the handler class
  • No business logic in the trigger body
  • No base class required
trigger UsageTrigger on Usage__c (after insert, after update) {
    switch on Trigger.operationType {
        when AFTER_INSERT {
            UsageTriggerHandler.afterInsertHandler(Trigger.new);
        }
        when AFTER_UPDATE {
            UsageTriggerHandler.afterUpdateHandler(Trigger.new, Trigger.oldMap);
        }
    }
}

Note: The Kevin O'Hara TriggerHandler framework is NOT used in this project. Do not add a TriggerHandler base class unless the user explicitly requests a full migration of all existing triggers to that pattern.


skill: create-apex-trigger-with-handler

Trigger phrase: "create a trigger" / "new trigger for"

Rules

  • One trigger per object. If a trigger already exists for the object, extend the existing handler class — do not create a second trigger.
  • Business logic goes in the handler class, never in the trigger body.
  • For recursion control, use a static Boolean flag on the handler class (no base class is present in this project).

Steps

  1. Check force-app/main/default/triggers/ — warn and stop if a trigger for this object already exists
  2. Create force-app/main/default/triggers/<Object>Trigger.trigger
    • Use switch on Trigger.operationType with only the required events
    • Each branch calls a static method on the handler: <Object>TriggerHandler.afterInsertHandler(Trigger.new)
    • No logic in the trigger body
  3. Create force-app/main/default/triggers/<Object>Trigger.trigger-meta.xml
    • apiVersion: 66.0, status: Active
  4. Create force-app/main/default/classes/<Object>TriggerHandler.cls
    • public with sharing class — no base class
    • Public static methods per event: afterInsertHandler(List<SObject> newRecords), afterUpdateHandler(List<SObject> newRecords, Map<Id,SObject> oldMap), etc.
    • Delegate to a service class for business logic — keep handler methods as thin dispatchers
  5. Create force-app/main/default/classes/<Object>TriggerHandler.cls-meta.xml
  6. Deploy command:
    sf project deploy start --metadata ApexTrigger:<Object>Trigger,ApexClass:<Object>TriggerHandler --target-org dev-org

skill: create-apex-class

Trigger phrase: "create an Apex class" / "new service class" / "new controller"

Class Types and Templates

TypeSharingKey Pattern
controllerwith sharing@AuraEnabled methods, Security.stripInaccessible() on results
servicewith sharingStatic methods, WITH SECURITY_ENFORCED on all SOQL
trigger-handlerwith sharingPublic static methods per event, delegates to service class
batchglobalImplements Database.Batchable<SObject>, start/execute/finish
schedulableglobalImplements Schedulable, execute(SchedulableContext sc)
queueablepublicImplements Queueable, execute(QueueableContext ctx)
test@IsTest@TestSetup, no SeeAllData=true, 90%+ coverage target

Naming Conventions

  • Handler classes: <ObjectName>TriggerHandler.cls
  • Service classes: <Domain>Service.cls
  • Controller classes: <Feature>Controller.cls
  • Test classes: <ClassName>Test.cls

Steps

  1. Create force-app/main/default/classes/<ClassName>.cls with correct template
  2. Create force-app/main/default/classes/<ClassName>.cls-meta.xml (apiVersion: 66.0, status: Active)
  3. Deploy command:
    sf project deploy start --metadata ApexClass:<ClassName> --target-org dev-org

skill: publish-platform-event

Trigger phrase: "publish a platform event" / "fire a platform event" / "push to platform event"

Use this pattern whenever Apex needs to publish a Platform Event — from a trigger handler, service class, or batch job.

Rules

  • Always use EventBus.publish() — never use insert for platform events
  • Always check Database.SaveResult after publishing — a publish can fail silently without the check
  • Use try/catch to handle unexpected exceptions and log them
  • Field mapping between source SObject and the event must be explicit — no dynamic field assignment
  • This pattern fires after insert or after update — never before context (records need IDs)

Pattern: Publish from a Service Class (animuscrm pattern)

public with sharing class UsageEventService {

    public static void publishEvents(List<Usage__c> usages, String eventType) {
        List<Platform_Usages__e> events = new List<Platform_Usages__e>();

        for (Usage__c u : usages) {
            Platform_Usages__e evt = new Platform_Usages__e();
            // CloudEvents envelope fields
            evt.specversion__c    = '1.0';
            evt.type__c           = eventType; // e.g. 'com.animuscrm.usage.created'
            evt.source__c         = URL.getOrgDomainUrl().toExternalForm();
            evt.subject__c        = u.Id;
            evt.time__c           = System.now();
            evt.datacontenttype__c = 'application/json';
            // Payload: JSON-serialise the Usage record
            evt.data__c           = JSON.serialize(u);
            events.add(evt);
        }

        try {
            List<Database.SaveResult> results = EventBus.publish(events);
            for (Integer i = 0; i < results.size(); i++) {
                if (!results.get(i).isSuccess()) {
                    for (Database.Error err : results.get(i).getErrors()) {
                        // Log using this org's Exception_Log__e fields
                        EventBus.publish(new Exception_Log__e(
                            Object__c          = 'Usage__c',
                            Operation__c       = 'PublishPlatformEvent',
                            Record_Id__c       = usages.get(i).Id,
                            Exception_Details__c = err.getStatusCode() + ': ' + err.getMessage()
                        ));
                    }
                }
            }
        } catch (Exception e) {
            EventBus.publish(new Exception_Log__e(
                Object__c          = 'Usage__c',
                Operation__c       = 'PublishPlatformEvent',
                Record_Id__c       = null,
                Exception_Details__c = e.getMessage() + '\n' + e.getStackTraceString()
            ));
        }
    }
}

Steps

  1. Determine which trigger events should publish (typically after insert, after update)
  2. Create the mapping list: for each source record, instantiate the __e SObject and assign fields explicitly
  3. Call EventBus.publish(eventList) and capture the List<Database.SaveResult>
  4. Iterate results — log any isSuccess() == false entries with the record ID and error message
  5. Wrap the entire method in try/catch(Exception e) and log unexpected failures
  6. Never put EventBus.publish() inside a loop — always bulk-collect events first, publish once
  7. This org's Exception_Log__e has these fields — always use these exact API names:
    • Object__c (Text 80) — the SObject being processed
    • Operation__c (Text 250) — the operation name (e.g. 'PublishPlatformEvent')
    • Record_Id__c (Text 18) — the affected record's ID
    • Exception_Details__c (LongTextArea 32768) — full error message and stack trace

Governor Limit Notes

  • EventBus.publish() counts against DML statement limits (150 per transaction)
  • Each published event counts against platform event daily limits (varies by org edition)
  • Bulk-publish in one call — never call EventBus.publish() inside a for loop

skill: enforce-security

Trigger phrase: "add security to" / "secure this class" / "fix security issues"

Steps

  1. Read the target Apex class in full
  2. For every SOQL query in @AuraEnabled, @RemoteAction, or @RestResource methods:
    • Add WITH SECURITY_ENFORCED to the query, OR
    • Use Security.stripInaccessible(AccessType.READABLE, results) before returning
  3. For every DML operation (insert, update, delete, upsert):
    • Add Schema.sObjectType.<Object>.isCreateable() before insert/upsert
    • Add Schema.sObjectType.<Object>.isUpdateable() before update/upsert
    • Add Schema.sObjectType.<Object>.isDeletable() before delete
  4. Confirm the class declaration uses with sharing
  5. Confirm no Database.query() uses string concatenation — replace with bind variables
  6. Report any remaining issues that require manual review

Security Checklist

  • with sharing on class declaration
  • WITH SECURITY_ENFORCED or stripInaccessible() on all exposed SOQL
  • DML guards (isCreateable, isUpdateable, isDeletable) in place
  • No hardcoded IDs (15 or 18 char strings starting with 00D, 001, 003, etc.)
  • No MD5 for tokens — use Crypto.generateDigest('SHA-256', ...) minimum
  • No string concatenation in Database.query() calls
  • Null checks before accessing related object fields (.Lookup__r.Field__c)

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.