We were recently taught that cancer occurs only in those cells which undergo cell division so, cancer is not possible in cardiac cells and neurons. But we know that till a certain age our heart grows in size so that means it goes under cell division. So doesn't that mean that cancer can also occur in heart cells?
As the other answer has already stated, there are cases of heart cancer. Just to expand on that answer further, according to this article, the rate of heart tumors is a mere 1.38 in 100,000 people per year and of that only around 10% are malignant (truly cancerous tumors) in nature. Just to put this into perspective of how low of a rate this is, the overall rate of cancer in the U.S. for both men and women combined is 352.2 per 100,000.[source]
Doing some rudimentary calculations, if the rate of malignant tumors is one tenth of 1.38 in 100,000, that means the rate of heart cancer is around 0.14 per 100,000! Just to add to how rare this is, the Mayo Clinic on average only sees around one case of heart cancer per year.[source]
Also, to clarify your statement about what types of cells can have cancer, it is not only dividing cells that can have cancer (even though the majority of cancer originates from cells undergoing a lot of cell division such as the skin and GI tract). While cell division by its nature causes a vast number of the mutations which would potentially lead to cancer, other environmental factors such as toxins and radiation could cause also cause similar mutations in cells that might not even be dividing.
Though very rare, primary cardiac tumours do exist.
Most of the 1° cardiac tumours are benign, malignancy occurence is pretty much low.
Give it a read— https://www.ncbi.nlm.nih.gov/pmc/articles/PMC3113129/