Are you setting the selection filter to Faces Only when Ctrl+A is called. In your code, you do not check the selection type. I think the selection type of all selected objects is not Faces and hence the Persistence IDs are different.
Hope it helps!!!
Perfect. Setting the selectionfilter works fine. Thanks