This post highlights an old method to retrieve last record. Coldfusion has changed a lot since then. Keep searching.
If you are a developer, there is no doubt that you have the need to retrieve the last record of a database insert without requiring another input from the end user. You want your user experience to appear as fluid as possible and an unnecessary multiple page submit does not accomplish that.
If you have a record that you will be inserting and need the ID of that just inserted record, your code will depend upon the database that you use. I will cover two of the most common DB’s used, MSSQL and MySQL.
Retrieve last record inserted (ID) if using Microsoft SQL Server (MSSQL):
I won’t go deep into the how and why, what I am looking to do is provide a basis for you to get over this little stumbling block. When using MSSQL, you can accomplish the task within your record insert query. I am assuming that you know the basics about inserting data using CF Query. I am also using <cfqueryparam> to protect my queries from hacks and to require particular datatypes. This has nothing to do with the key retrieval, it is just good practice.