from typing import Dict


def parse_sf_record(nested_dict: Dict) -> Dict:
    """Recursively parse the nested dictionaries returned by Salesforce Simple API
    library.
    :param nested_dict: Nested dictionary object
    :return: Flattened dictionary representing record
    """

    clean_dict: Dict = {}

    for k, v in nested_dict.items():
        if k == "attributes" or v is None:
            continue
        elif isinstance(v, dict):
            clean_child_dict = parse_sf_record(v)

            for child_key, child_clean_value in clean_child_dict.items():
                clean_key = f"{k}.{child_key}"
                clean_dict[clean_key] = child_clean_value
        else:
            clean_dict[k] = v

    return clean_dict