Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions rules/S8035/apex/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"title": "Change Data Capture event objects should follow the correct naming convention",
"type": "BUG",
"status": "ready",
"remediation": {
"func": "Constant/Issue",
"constantCost": "5 min"
},
"tags": [
"salesforce",
"cdc",
"naming"
],
"defaultSeverity": "Blocker",
"ruleSpecification": "RSPEC-8035",
"sqKey": "S8035",
"scope": "Main",
"defaultQualityProfiles": [
"Sonar way"
],
"quickfix": "unknown",
"code": {
"impacts": {
"RELIABILITY": "BLOCKER",
"MAINTAINABILITY": "BLOCKER"
},
"attribute": "CONVENTIONAL"
}
}
49 changes: 49 additions & 0 deletions rules/S8035/apex/rule.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
This is an issue when creating triggers for Change Data Capture events using incorrect object naming patterns that will cause compilation errors.

== Why is this an issue?

Change Data Capture (CDC) in Salesforce requires specific naming conventions for event objects to function correctly. The platform automatically generates these event objects based on the underlying Salesforce objects, and triggers must reference them using the exact naming pattern.

For standard Salesforce objects (like Account, Contact, Opportunity), the event object name follows the pattern `StandardObjectNameChangeEvent`. For example, changes to Account records generate `AccountChangeEvent` objects.

For custom objects (those ending with `__c`), the event object name follows the pattern `CustomObjectName__ChangeEvent`. For example, if you have a custom object called `Employee__c`, its change events are captured in `Employee__ChangeEvent`.

Using incorrect naming conventions will result in compilation errors because the Salesforce platform cannot find the referenced event object. This prevents the trigger from being saved or deployed, blocking the implementation of asynchronous processing logic that depends on Change Data Capture.

=== What is the potential impact?

Using incorrect naming conventions for Change Data Capture event objects will cause compilation errors, preventing the trigger from being deployed or executed. This blocks the implementation of real-time data synchronization and asynchronous processing workflows that depend on Change Data Capture functionality.

== How to fix it

For standard Salesforce objects, use the naming pattern `StandardObjectNameChangeEvent` without any underscores.

=== Code examples

==== Noncompliant code example

[source,apex,diff-id=1,diff-type=noncompliant]
----
trigger AsyncAccountTriggers on Account__ChangeEvent (after insert) {
// Incorrect naming for standard object - includes unnecessary underscores
// This will cause a compilation error
}
----

==== Compliant solution

[source,apex,diff-id=1,diff-type=compliant]
----
trigger AsyncAccountTriggers on AccountChangeEvent (after insert) {
// Correct naming for standard object
// Standard objects use: ObjectNameChangeEvent
}
----

== Resources

=== Documentation

* Change Data Capture Developer Guide - https://developer.salesforce.com/docs/atlas.en-us.change_data_capture.meta/change_data_capture/[Official Salesforce documentation for Change Data Capture implementation and best practices]

* Apex Triggers for Change Events - https://developer.salesforce.com/docs/atlas.en-us.change_data_capture.meta/change_data_capture/cdc_trigger.htm[Documentation on creating Apex triggers for Change Data Capture events]
2 changes: 2 additions & 0 deletions rules/S8035/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
}
Loading