def sortMultiEntityFieldsByID(schema, entity):
    """
    Sort all multi-entity fields in an entity by their ID.

    Args:
        schema (dict): Shotgun Schema
        entity (dict): Entity dictionary

    Returns:
        dict: entity with fields sorted
    """
    result = {}
    entitySchema = schema[entity['type']]
    for field, val in entity.items():
        if field in ['id', 'type']:
            result[field] = val
            continue

        fieldSchema = entitySchema[field]
        dataType = fieldSchema['data_type']['value']
        if dataType == 'multi_entity':
            val = sorted(val, key=lambda e: e['id'])
        result[field] = val
    return result