[apex] Verify EmptyIfStmt and EmptyStatementBlock with triggers

This commit is contained in:
Andreas Dangel 2024-09-06 19:43:07 +02:00
parent fe0d05d8d5
commit 1038eaa283
No known key found for this signature in database
GPG Key ID: 93450DF2DF9A3FA3
2 changed files with 54 additions and 0 deletions

View File

@ -30,4 +30,29 @@ public class Foo {
}
]]></code>
</test-code>
<test-code>
<description>EmptyIfStatement in trigger (#5138)</description>
<expected-problems>1</expected-problems>
<expected-linenumbers>9</expected-linenumbers>
<code><![CDATA[
// https://github.com/SalesforceLabs/chatter-delete-blocker/blob/master/src/triggers/DisableFeedPostDeletes.trigger
/**
* Author: Marcus Ericsson - mericsson@salesforce.com
*/
trigger DisableFeedPostDeletes on FeedItem (before delete)
{
if (!DisableChatterDeleteDelegate.allowDelete()) {
for(FeedItem f : Trigger.old){
if (((String)f.parentId).startsWith('00Q') && f.type == 'TrackedChange') {
// ok to ignore
}
else {
f.addError('Your administrator has disabled feed post and comment deletions.');
}
}
}
}
]]></code>
</test-code>
</test-data>

View File

@ -143,6 +143,35 @@ public class Foo {
}
}
}
]]></code>
</test-code>
<test-code>
<description>EmptyStatementBlock in trigger (#5138)</description>
<expected-problems>1</expected-problems>
<expected-linenumbers>18</expected-linenumbers>
<code><![CDATA[
// https://github.com/SalesforceLabs/chatter-delete-blocker/blob/master/src/triggers/DisableFeedPostDeletes.trigger
/**
* Author: Marcus Ericsson - mericsson@salesforce.com
*/
trigger DisableFeedPostDeletes on FeedItem (before delete)
{
if (!DisableChatterDeleteDelegate.allowDelete()) {
for(FeedItem f : Trigger.old){
if (((String)f.parentId).startsWith('00Q') && f.type == 'TrackedChange') {
// ok to ignore
}
else {
f.addError('Your administrator has disabled feed post and comment deletions.');
}
}
}
public void setBar(Integer bar) {
// empty
}
}
]]></code>
</test-code>
</test-data>