As a follow-up to my first question, "How to create a new case and return the case by clicking a button" -- I need to extend the standard controller case with an extension, but when I create a new case, I need the CASE-ID for the extension.
I know the code to get the CASE-ID would be:
caseRecord = (Case)controller.getRecord();
...but this does not work, since a new case does not appear to have a CASE-ID until after it is saved.
How to get Case ID on a new Case page?
Attribution to: Lance Shi
Possible Suggestion/Solution #1
You can't get access to the id until the record is saved, as no id exists prior to that point. The way I've handled this in the past is to override the new button with a small Visualforce page that has an action attribute on the page component. The action method invoked by this inserts a case with the minimum number of fields populated and then redirects the user to the edit page for the new case.
The downside to this is that you can end up with orphaned records - i.e. those that were created through this mechanism and then the user changed their mind. There are a few ways to try to mitigate against this (overriding the edit page so that cancel deletes the case, the first edit taking place in a visualforce page, scheduled apex to clean them up), none of which solve the problem 100%.
Attribution to: Bob Buzzard
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/31713