I'm triying to retrive a record from Product2 using an internal product code placed on lead object every time a lead is inserted. This product code on lead entity is called "Program__c" (picklist field). The query seems to give an empty result but if this query is made directly in query editor, it works. However, if I make a query directly to de lead object, it works too. This class is called by a trigger:
public class HelloWorld {
public static void Hola(List<Lead> leadList){
system.debug(leadList);
for(Lead l : leadList){
//This query is working
List <Lead> le = [Select id, name from lead where Id =: l.Id LIMIT 1];
//Debug showing id and name info
system.debug(le);
//This query is not working
List <Product2> p = [Select id, name from product2 where ProductCode = : l.Program__c LIMIT 1];
//Empty debug
system.debug(p);
}
}
}
Thanks all in advance.
Alex.
23 answers
so basically you are testing this by using the above mentioned Test class? in that case you have create a product2 which has productcode value = 'MBA'