Extrasystoles lead to several consequences, ranging from uneventful palpitations to lethal ventricular arrhythmias, in the presence of pathologies, such as myocardial ischemia. The role of working versus conducting cardiomyocytes, as well as the tissue requirements (minimal cell number) for the generation of extrasystoles, and the properties leading ectopies to become arrhythmia triggers (topology), in the normal and diseased heart, have not been determined directly in vivo. Here, we used optogenetics in transgenic mice expressing ChannelRhodopsin-2 selectively in either cardiomyocytes or the conduction system to achieve cell type-specific, noninvasive control of heart activity with high spatial and temporal resolution. By combining measurement of optogenetic tissue activation in vivo and epicardial voltage mapping in Langendorff-perfused hearts, we demonstrated that focal ectopies require, in the normal mouse heart, the simultaneous depolarization of at least 1,300–1,800 working cardiomyocytes or 90–160 Purkinje fibers. The optogenetic assay identified specific areas in the heart that were highly susceptible to forming extrasystolic foci, and such properties were correlated to the local organization of the Purkinje fiber network, which was imaged in three dimensions using optical projection tomography. Interestingly, during the acute phase of myocardial ischemia, focal ectopies arising from this location, and including both Purkinje fibers and the surrounding working cardiomyocytes, have the highest propensity to trigger sustained arrhythmias. In conclusion, we used cell-specific optogenetics to determine with high spatial resolution and cell type specificity the requirements for the generation of extrasystoles and the factors causing ectopies to be arrhythmia triggers during myocardial ischemia.