== Why is this an issue?

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

[source,apex]
----
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[]
