Officers discovered Craig Dimelow, 28, with nearly two kilos of the Class A drug, quantities of adulterant and equipment used for cutting the drug.
Detective Inspector Grant Hendry, from the East Organised Crime and Counter Terrorism Unit, said: "This was a significant recovery of heroin which we believe would've been sold across Edinburgh, Fife and East Lothian. Intelligence gathered from our officers ensured this couldn't be sold within our communities. The success of this operation couldn't have been achieved without the support of local communities.
"The condition we found the flat in showed a haphazard and flippant approach to dealing with a drug that has such a devastating effect on people.
"Tackling organised crime, which includes drug offences, remains one of Police Scotland's top priorities which this enforcement activity demonstrates. Any intelligence we receive relating to crimes of this nature will be acted upon.
"If you would like to report ongoing drug crime in your area then please contact us on 101 or make an anonymous report to the charity Crimestoppers on 0800 555 111."
Dimelow, a self-employed painter and decorator, was seen to arrive at the flat on October 31 last year with another man in a van and both went into the close at Captains Drive empty handed.
Dimelow left minutes later with a bulky carrier bag and the pair then drove to a car park at Dalgety Bay, Fife.
The other man took a pair of white overalls from the van and put them in a litter bin with Dimelow in attendance.
After gathering intelligence police were granted search warrants for the flat in Captain's Drive and Dimelow's home in Leving Place, Livingston.
When they turned up at the Gilmerton flat they found Dimelow was there alone with almost two kilos of heroin, 38 kilos of paracetamol and caffeine used to cut the Class A drug, along with face masks, sieves and a press.
A further search at his home in West Lothian turned up £10,740 in cash.
Dimelow admitted being concerned in the supply of heroin between October 31 and November 21 last year, when he appeared in court.
Unemployed benefit claimant Newlands pled guilty to possessing a prohibited weapon, the stun gun.