I have a feature class and I need to know the ObjectID of its last record.

What is the best way to find out last ObjectID?

Opening a search cursor and reading all the records is one way, but is there any other way?

  • In a shapefile or database feature class? – Michael Stimson Aug 22 '14 at 2:57
  • In Database feature class , data set is in versioned SDE database – shafey Aug 22 '14 at 3:59
  • 1
    Refer the answer by PolyGeo. Shapefiles are special in that their FIDs compress after editing so (outside of edits) their FIDs are unique/ascending with no gaps. Database feature classes retain the same OBJECTID for the feature and do not reuse expired values so they, although unique, can have gaps. – Michael Stimson Aug 22 '14 at 4:02
  • 2
    Would you elaborate why do you need an ObjectID in first place? This is a system field which is maintained by ArcGIS and in general you don't want to build any business logic on this field. And by "last record", do you refer to the last edited/created feature? – Alex Tereshenkov Aug 22 '14 at 5:44
  • Actually , I have a feature class , that have no primary key to identify the individual records , I have a tool that inserted records onto feature class , before I insert I need to know what is the last record objectid – shafey Sep 5 '14 at 1:54

To do this I would use the Summary Statistics (Analysis) tool and this statistic type on ObjectID:

MAX—Finds the largest value for all records of the specified field.

Then if you want to read the MAX (highest) value you can use a search cursor on its output table to open and read the one record therein.

  • This is not a reliable solution. In a multi-editor scenario, Editor1 might take the sequence value that allocates 201-400, and Editor2 would take 401-600, then Editor2 could only add one feature (401) and exit, then Editor1 could add features 201-392. Using the above algorithm, every "last" edit by Editor1 would be incorrectly identified as 401. – Vince May 8 '17 at 23:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.