Cadbury changed its quality-testing systems, allowing salmonella to enter its chocolate bars, in order to save money, a court has been told.
More than one million chocolate bars had to be recalled
The firm has admitted charges relating to an outbreak in which 30 people fell ill and one million bars were recalled.
Birmingham Crown Court heard the firm introduced an "allowable tolerance level" at its Herefordshire factory.
The firm has apologised for not realising a leaking pipe at the Marlbrook plant posed a health risk.
Salmonella was found in some of the firm's products between January and March 2006 and the firm recalled many of its products on 23 June.
The firm pleaded guilty earlier this month to breaching food and hygiene regulations in relation to the outbreak.
It also emerged in court that some of those who were made ill by infected chocolate had to receive hospital treatment.
One person began to vomit blood, a 61-year-old woman lost 10lbs in weight and another woman was so ill she could not attend her sister-in-law's funeral.
Barry Berlin, prosecuting Cadbury on behalf of Birmingham City Council, said the company's change to its quality testing systems in 2003 was "utterly inappropriate".
Mr Berlin said: "Large quantities of product were being destroyed and Cadbury's were looking for ways of avoiding that and that's what they did.
"There is no dispute that there is a linkage between the chocolate that was distributed by Cadbury and the poisoning that took place later on."
He added that salmonella cells could survive in chocolate for years.
The company was expected to be sentenced on Friday, but it was held off until Monday.
Cadbury's barrister told a previous hearing that the company had already spent more than £20m on improvements since the outbreak, including changes to quality control procedures.
Birmingham City Council is responsible for enforcing health and safety laws at Cadbury's plant in Bournville.
Separately Herefordshire Council is also prosecuting the company over the state of its factory near Leominster where the bars originated.
In a statement issued after Friday's proceedings, a spokesman for Cadbury said: "Quality has always been at the heart of our business, but the process we followed in the UK in this instance has been shown to be unacceptable.
"We have apologised for this and do so again today. In particular, we offer our sincere regrets and apologies to anyone who was made ill as a result of this failure."