function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
RyanhRyanh 

Best way to get the Id of a new record back after insert/upsert operation

I've customized the standard controller save action with a controller extension. After saving the master record, I need to be able to create a couple new child records. In order to create the child records with a reference back to the master, I need the ID of the master after it was saved.

 

The only way I was able to figure out a way to do that was to parse the URL from the PageReference returned after the stdController.save() method completes:

 

view_io = stdController.save(); ... String ioId = view_io.getUrl().substring(1);

 

this is pretty lame though... Is there a better way?