We can utilize Tooling API to get information of all fields present in a object. You can put different filters like to get all fields or specific fields like auto number fields, ExternalID fields etc.
Below is apex class which contains method to get all fields. Remember that callout uses Named Credential in order to do handshake with SFDC org.
This method contains 3 parameters:
- I have added filter not to return auto number fields. If you want to get those fields details then remove it from query string.
- If you want to query only External Id fields then specify filter as DataType+Like+\'%25(External+ID)%25\'';