Ensure objectId is set only when required