Yes, it is sometimes a good idea to hard-code values (for example, while learning Apex or Process Builder or hard code Pie value i.e. 3.14), but there’s no simple rule as to when; it depends completely on context. If you’re hard coding the value of the earth’s gravitational constant, no one’s going to care. If you hard code the record ID (Queue, Group or Salesforce record Id, etc.), you’re in for trouble. Time and time again, I see Apex code, Flows or Processes that contains hard-coded Ids, whether it’s the Description field, a user ID, or even a group ID, etc. The problem with hard coding IDs is that any changes need to be made to the Flow or Process itself, test again, and then deploy to production org. The record IDs can change, for example between a sandbox and a production environment. It might be possible that a queue (Dupe Management) has different ID in a sandbox and a Production org. Let’s start with a business use case
Business Use case: – Donna Serdula is working as System administrator at Universal Containers. She has received a requirement from higher management whenever an account is created for Industry Not For Profit, auto create a case and assign it to Nonprofit Experts queue to verify organization’s nonprofit status.
Solution of above business requirement
To solve the above business requirement, first of all, we have to create a queue as shown in the following screenshot
Now you can refer the Queue id while creating a case through Process Builder.
The problem with this approach (Hard-coding queue ID) is, If you are developing in the Sandbox, the IDs of the newly created Queue will change when you get to Production, and you have to do the rework.
–> As per Salesforce best practice, everyone will suggest you don’t Hardcode IDs, Query for them.
It is always good to follow Salesforce best practices where possible. At the moment Process Builder doesn’t allow to query and save the outcome (means record ID, field value, etc.) in a variable, even you can’t save newly created case ID (case created through Create a Record – process action) in a variable.