I have written one trigger and it's been working in Production for the last year. Now I have created one more trigger on same Object(Company__c). There is no SOQL statements. Now validate my new trigger in Production at the time old trigger the validation is failing. I got a following validation error:
Error: Failure Message: "System.LimitException: Too many SOQL queries: 101", Failure Stack Trace: "Trigger.DirectCompany: line 8, column 1"
My trigger trigger can handled bulkyfied or not I need to change my trigger?
Old Trigger:
Trigger DirectCompany on Company__c(AFTER INSERT,AFTER UPDATE)
{
TRY
{
LIST<Product__c> sapili = NEW LIST<Product__c>() ;
LIST<String> orderEstmate = NEW LIST<String>();
LIST<Product__c> sapiord = [SELECT Id ,Text02__c FROM Product__c WHERE Text02__c !=: '' ORDER BY Id DESC];//LIMIT 50000
String orderId;
FOR( Company__c TempOrder : TRIGGER.NEW)
{
IF(TempOrder.Conform__c == TRUE && TempOrder.Estimate__c.trim() != NULL)
orderEstmate.add(TempOrder.Estimate__c.trim());
}
LIST<Sub_Product__c> bidproli = [SELECT Id,Name FROM Sub_Product__c WHERE Name IN : orderEstmate];
FOR( Company__c com : TRIGGER.NEW)
{
IF(com.Conform__c == TRUE && com.Estimate__c != NULL)
{
IF(bidproli.SIZE() != 0)
{
String Text2 = '';
FOR(Product__c notsapi : sapiord )
{
Text2 = Text2 + notsapi.Text02__c.trim().substringBefore('|')+', ';
}
IF(Text2.contains(com.Id))
{
BREAK;
}
orderId = com.Id;
FOR(Sub_Product__c bidpro : bidproli)
{
IF(bidpro.Name.Trim().equals(com.Estimate__c.trim()))
{
//Here my own logic here
sapili.add(sapi);
BREAK ;
}
}
}
}
}
IF(sapili.size() != 0)
INSERT sapili;
}
CATCH(EXCEPTION E)
{
SYSTEM.DEBUG(E);
}
}
New Trigger:
Trigger DeleteCompany on Company__c(AFTER INSERT,AFTER UPDATE)
{
LIST<Company__c> deletecom = new LIST<Company__c>();
FOR(Company__c order : [SELECT Id,Delete__c FROM Company__c WHERE Id IN : Trigger.NEW])
{
IF((order.Delete__c == TRUE))
deletecom.add(order);
}
IF(deletecom.SIZE() != 0)
DELETE deletecom;
}
Limitsclass(It's always good to have this). http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_limits.htm – highfive May 06 '14 at 08:32