rspec/rules/S5379/apex/rule.adoc

42 lines
1.3 KiB
Plaintext
Raw Normal View History

== Why is this an issue?
2021-04-28 16:49:39 +02:00
Salesforce Record Ids vary across environments. Thus if a Record Id is hardcoded in Apex code, the code may not work as expected when it is deployed in another environment. This happens because the environment in which the code is deployed may not have the same hardcoded record Id. Hence it is a best practice to avoid hard coding record Ids.
This rule raises an issue when it detects hardcoded record Ids, i.e. strings which contain 15 or 18 characters and which start with any of the prefixes https://help.salesforce.com/articleView?id=000005995&language=en_US&type=1[listed by Salesforce]
=== Noncompliant code example
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,apex]
2021-04-28 16:49:39 +02:00
----
for(Case c: Trigger.new){
if(c.RecordTypeId=='012500000009tuy'){ // Noncompliant
// ...
} else if(c.RecordTypeId=='0123000000095Kmwer'){ // Noncompliant
// ...
}
}
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Replace this hardcoded record ID
'''
== Comments And Links
(visible only on this page)
=== on 14 Aug 2019, 13:35:44 Quentin Jaquier wrote:
This rule raises a lot of false positives on test files, therefore, we decided to only report hard-coded IDs on main sources.
endif::env-github,rspecator-view[]