A structured approach on when to suspect an immunodeficiency and the initial investigations pathway is given in the publication by Grammatikos et al. Immunodeficiency and autoimmunity
There are a large number of immunodeficiency syndromes that present clinical and laboratory characteristics of autoimmunity. The decreased ability of the immune system to clear infections in these patients may be responsible for causing autoimmunity through perpetual immune system activation. One example is common variable immunodeficiency (CVID) where multiple autoimmune diseases are seen, e.g., inflammatory bowel disease, autoimmune thrombocytopenia, and autoimmune thyroid disease. Familial hemophagocytic lymphohistiocytosis, an autosomal recessive primary immunodeficiency, is another example. Low blood levels of red blood cells, white blood cells, and platelets, rashes, lymph node enlargement, and enlargement of the liver and spleen are commonly seen in these patients. Presence of multiple uncleared viral infections due to lack of perforin are thought to be responsible. In addition to chronic and/or recurrent infections many autoimmune diseases including arthritis, autoimmune hemolytic anemia, scleroderma and type 1 diabetes are also seen in X-linked agammaglobulinemia (XLA). Recurrent bacterial and fungal infections and chronic inflammation of the gut and lungs are seen in chronic granulomatous disease (CGD) as well. CGD is caused by a decreased production of nicotinamide adenine dinucleotide phosphate (NADPH) oxidase by neutrophils. Hypomorphic RAG mutations are seen in patients with midline granulomatous disease; an autoimmune disorder that is commonly seen in patients with granulomatosis with polyangiitis and NK/T cell lymphomas. Wiskott–Aldrich syndrome (WAS) patients also present with eczema, autoimmune manifestations, recurrent bacterial infections and lymphoma.
The characteristics of lacking and/or impaired antibody functions can be related to illnesses such as X-Linked Agammaglobulinemia and Common Variable Immune Deficiency

Secondary immunodeficiencies
Secondary immunodeficiencies, also known as acquired immunodeficiencies, can result from various immunosuppressive agents, for example, malnutrition, aging, particular medications (e.g., chemotherapy, disease-modifying antirheumatic drugs, immunosuppressive drugs after organ transplants, glucocorticoids) and environmental toxins like mercury and other heavy metals, pesticides and petrochemicals like styrene, dichlorobenzene, xylene, and ethylphenol. For medications, the term immunosuppression generally refers to both beneficial and potential adverse effects of decreasing the function of the immune system, while the term immunodeficiency generally refers solely to the adverse effect of increased risk for infection. Many specific diseases directly or indirectly cause immunosuppression. This includes many types of cancer, particularly those of the bone marrow and blood cells (leukemia, lymphoma, multiple myeloma), and certain chronic infections. Immunodeficiency is also the hallmark of acquired immunodeficiency syndrome (AIDS), caused by the human immunodeficiency virus (HIV). HIV directly infects a small number of T helper cells, and also impairs other immune system responses indirectly. Various hormonal and metabolic disorders can also result in immune deficiency including anemia, hypothyroidism and hyperglycemia. Smoking, alcoholism and drug abuse also depress immune response. Heavy schedules of training and competition in athletes increases their risk of immune deficiencies. Diagnosis
Patients with immune deficiencies can present with variable clinical phenotypes. This often translates into a significant delay in their diagnosis, and resultant patient morbidity.