Missing method for retrieving express entry ID from Express Entry Builder

Permalink
Using the code fromhttps://documentation.concrete5.org/developers/express/creating-read... to insert a new express data entry:
$entry = Express::buildEntry('student')
        ->setStudentFirstName('Andrew')
        ->setStudentLastName('Embler')
        ->setStudentContactAddress($address)
        ->save();

Next I need to retrieve the express entry ID from the recently created entry:
$entryId = $entry->getID();

This fails as the Express Entry Builder lacks a getID() method...

Wow can I retrieve the express entry ID from the recently created entry?

tdausner
 
PineCreativeLabs replied on at Permalink Reply
PineCreativeLabs
I'm also wondering about this. Can anyone help with this?
mnakalay replied on at Permalink Reply
mnakalay
This is weird. The save() function returns the entry itself which is confirmed by the docs "The $entry object here is the full Concrete\Core\Entity\Express\Entry"

The class Concrete\Core\Entity\Express\Entry does contain a getID() function as well as a jsonSerialize() function that will return an array containing both the entry's label and ID.

Could you do a get_class() on your $entry object to check what class it really is?
tdausner replied on at Permalink Reply
tdausner
As expected get_class($entry) returns Concrete\Core\Express\EntryBuilder
mnakalay replied on at Permalink Best Answer Reply
mnakalay
That's really strange. As I said the save function really returns the Entry. So let's try something really stupid but you never know it might work.

What do you get if you try
$builder = Express::buildEntry('student')
        ->setStudentFirstName('Andrew')
        ->setStudentLastName('Embler')
        ->setStudentContactAddress($address);
$entry = $builder->save();
tdausner replied on at Permalink Reply
tdausner
Great solution!. Yes, this works:
$entry = $builder->save();
$entryClass = get_class($entry); # returns 'Concrete\Core\Entity\Express\Entry'
$entryId = $entry->getID(); # returns the new entry ID

In short:
$entryId = $entry->save()->getID();

Thank you for great support.