Leeds Crown Court was told that Mohammed Kamran had been working in his community as a volunteer and turned his life around after being caught with drugs and thousands of pounds in cash in Ossett.
Prosecutor Satpal Roth-Sharma said Kamran's white Seat Leon had been clocked speeding by officers on Station Road in Ossett on January 1, 2020.
When they pulled him over, they found bags of cannabis in the centre console and a large amount of cash in his pocket - totalling £2,635 - and could not explain where it came from.
He was strip searched at the police station and several wraps of white and brown powder were found, along with a mobile phone. The powder was later confirmed to be heroin.
Kamran, of Emsley Close, Bradford, gave no comments during his police interview.
Due to the delays in the case, including the Covid-19 lockdowns, he was not summoned to appear at Leeds Magistrates' Court until April of this year where he admitted possession of heroin with intent to supply, and possession of cannabis.
Mitigating, Gerald Hendron, said: "He was 19 at the time of the offence and he is now 21, he was young man.
"He is genuinely racked with remorse for what he has done. He has brought shame on his reputable family."
He said that Kamran, who has no previous convictions, had been "giving back" by doing voluntary work in his community since his arrest and had turned his back on drug dealing.
The judge, Recorder Richard Thyne QC, told Karman: "You were dealing drugs on behalf of somebody else, which means it was a significant role.
"I accept there's genuine remorse. Some 19-year-olds are easily open to influence.
"If you were sent to prison you would be mixing with more sophisticated criminals and you'd be likely to offend in future.
"You have come very close to going to prison, understand how close you have come."
He gave him two years' jail, suspended for two years, 200 hours of unpaid work and a three-month electronic tag curfew.