In order to keep drug crime to a minimum in California, officers are often on the lookout for any signs of drug use or drug presence when they are investigating other crimes. For example if you are pulled over for erratic driving or a problem with your vehicle and an officer sees drugs on your dashboard, you could face criminal charges. However, there are limits to how far officers are allowed to search.
In general, the ruling is that they need to be in plain view, or you need to have given police permission to search in the place they found the illegal substance. So if you agree that officers can look in your trunk and they find drugs there, this could be used in evidence against you. However, if they forced their way into a locked compartment without your permission, this is generally considered to be unlawful seizure, so the drugs are not permissible evidence.
Furthermore, if the traffic stop itself was not legal, this could also invalidate the evidence provided by the drugs. On top of this, as this article on drug charges explains, even if the substances were lawfully seized, it still falls to the prosecution to prove beyond reasonable doubt that the drugs were yours and that they were definitely the illegal substance they were claimed to be.
It can seem like a lot to consider, especially when you are overburdened by worry about the possible consequences of conviction. Fortunately an attorney may be able to help you through. He or she can advise you on possible defense options and may be able to help you prepare for your trial.