From 3c99d91af55cf1bb944fcd4c1a1c7f5b8f7858b0 Mon Sep 17 00:00:00 2001 From: denis-troller Date: Mon, 29 Sep 2025 12:58:56 +0000 Subject: [PATCH 1/3] Create rule S8035 --- rules/S8035/apex/metadata.json | 25 +++++++++++++++++++ rules/S8035/apex/rule.adoc | 44 ++++++++++++++++++++++++++++++++++ rules/S8035/metadata.json | 2 ++ 3 files changed, 71 insertions(+) create mode 100644 rules/S8035/apex/metadata.json create mode 100644 rules/S8035/apex/rule.adoc create mode 100644 rules/S8035/metadata.json diff --git a/rules/S8035/apex/metadata.json b/rules/S8035/apex/metadata.json new file mode 100644 index 00000000000..a2df16f6926 --- /dev/null +++ b/rules/S8035/apex/metadata.json @@ -0,0 +1,25 @@ +{ + "title": "FIXME", + "type": "CODE_SMELL", + "status": "ready", + "remediation": { + "func": "Constant\/Issue", + "constantCost": "5min" + }, + "tags": [ + ], + "defaultSeverity": "Major", + "ruleSpecification": "RSPEC-8035", + "sqKey": "S8035", + "scope": "All", + "defaultQualityProfiles": ["Sonar way"], + "quickfix": "unknown", + "code": { + "impacts": { + "MAINTAINABILITY": "HIGH", + "RELIABILITY": "MEDIUM", + "SECURITY": "LOW" + }, + "attribute": "CONVENTIONAL" + } +} diff --git a/rules/S8035/apex/rule.adoc b/rules/S8035/apex/rule.adoc new file mode 100644 index 00000000000..3edb7d8d0d2 --- /dev/null +++ b/rules/S8035/apex/rule.adoc @@ -0,0 +1,44 @@ +FIXME: add a description + +// If you want to factorize the description uncomment the following line and create the file. +//include::../description.adoc[] + +== Why is this an issue? + +FIXME: remove the unused optional headers (that are commented out) + +//=== What is the potential impact? + +== How to fix it +//== How to fix it in FRAMEWORK NAME + +=== Code examples + +==== Noncompliant code example + +[source,apex,diff-id=1,diff-type=noncompliant] +---- +FIXME +---- + +==== Compliant solution + +[source,apex,diff-id=1,diff-type=compliant] +---- +FIXME +---- + +//=== How does this work? + +//=== Pitfalls + +//=== Going the extra mile + + +//== Resources +//=== Documentation +//=== Articles & blog posts +//=== Conference presentations +//=== Standards +//=== External coding guidelines +//=== Benchmarks diff --git a/rules/S8035/metadata.json b/rules/S8035/metadata.json new file mode 100644 index 00000000000..2c63c085104 --- /dev/null +++ b/rules/S8035/metadata.json @@ -0,0 +1,2 @@ +{ +} From 905fb289cd2f4999a6b554d9c24ee94c523acca5 Mon Sep 17 00:00:00 2001 From: denis-troller Date: Mon, 29 Sep 2025 22:18:39 +0200 Subject: [PATCH 2/3] Update rules/S8035/apex/rule.adoc in PR #5641 --- rules/S8035/apex/rule.adoc | 45 +++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/rules/S8035/apex/rule.adoc b/rules/S8035/apex/rule.adoc index 3edb7d8d0d2..ac470fabb1c 100644 --- a/rules/S8035/apex/rule.adoc +++ b/rules/S8035/apex/rule.adoc @@ -1,16 +1,22 @@ -FIXME: add a description - -// If you want to factorize the description uncomment the following line and create the file. -//include::../description.adoc[] +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? -FIXME: remove the unused optional headers (that are commented out) +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? +=== 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 -//== How to fix it in FRAMEWORK NAME + +For standard Salesforce objects, use the naming pattern `StandardObjectNameChangeEvent` without any underscores. === Code examples @@ -18,27 +24,26 @@ FIXME: remove the unused optional headers (that are commented out) [source,apex,diff-id=1,diff-type=noncompliant] ---- -FIXME +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] ---- -FIXME +trigger AsyncAccountTriggers on AccountChangeEvent (after insert) { + // Correct naming for standard object + // Standard objects use: ObjectNameChangeEvent +} ---- -//=== How does this work? - -//=== Pitfalls +== Resources -//=== Going the extra mile +=== 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] -//== Resources -//=== Documentation -//=== Articles & blog posts -//=== Conference presentations -//=== Standards -//=== External coding guidelines -//=== Benchmarks + * 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] From 2d5eae6e5b9b517ee69d64dbf9c94ca2a1d15230 Mon Sep 17 00:00:00 2001 From: denis-troller Date: Mon, 29 Sep 2025 22:18:42 +0200 Subject: [PATCH 3/3] Update rules/S8035/apex/metadata.json in PR #5641 --- rules/S8035/apex/metadata.json | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/rules/S8035/apex/metadata.json b/rules/S8035/apex/metadata.json index a2df16f6926..9a9ccf26d50 100644 --- a/rules/S8035/apex/metadata.json +++ b/rules/S8035/apex/metadata.json @@ -1,25 +1,29 @@ { - "title": "FIXME", - "type": "CODE_SMELL", + "title": "Change Data Capture event objects should follow the correct naming convention", + "type": "BUG", "status": "ready", "remediation": { - "func": "Constant\/Issue", - "constantCost": "5min" + "func": "Constant/Issue", + "constantCost": "5 min" }, "tags": [ + "salesforce", + "cdc", + "naming" ], - "defaultSeverity": "Major", + "defaultSeverity": "Blocker", "ruleSpecification": "RSPEC-8035", "sqKey": "S8035", - "scope": "All", - "defaultQualityProfiles": ["Sonar way"], + "scope": "Main", + "defaultQualityProfiles": [ + "Sonar way" + ], "quickfix": "unknown", "code": { "impacts": { - "MAINTAINABILITY": "HIGH", - "RELIABILITY": "MEDIUM", - "SECURITY": "LOW" + "RELIABILITY": "BLOCKER", + "MAINTAINABILITY": "BLOCKER" }, "attribute": "CONVENTIONAL" } -} +} \ No newline at end of file