function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
FlorentFlorent 

Multiple trigger deployment

Hello all,

 

Having received invaluable help on this forum to help me finish off my test units, I am now trying to deploy the trigger I've been working on for the opportunity object.

 

PROBLEM #1

Trouble is, in the organization I work for, a entity with multiple companies, there are already 2 existing opportunities' triggers, that were deployed before I took over the admin role (and people left the company…).

 

So, how do I go around this ?

 

- should my test class cover testing for other triggers as well ? But then, shouldn't other triggers' test classes cover my trigger's code as well? So in fact, would I have to deploy them again ?…

 

- should I include, in my trigger, the code from already existing triggers ? And then delete other triggers before deploying mine ?…

 

PROBLEM #2

Also, to make things even more fun, there is a test class for a trigger that is not working properly (anymore?)… I tried to validate my own trigger, to see what was happening, and it fails with the following error message :

 

API NameTypeLineColumnProblem

TESTprojectNUmberBUonOpportunity.myUnitTest()Class2021Failure Message: "System.LimitException: Too many SOQL queries: 101", Failure Stack Trace: "Trigger.ProjectNumberBUonOpportunity: line 202, column 1"

 

Of course, I can't edit this trigger in production…

Best Answer chosen by Admin (Salesforce Developers) 
cmlcml

Problem #1 :  Having multiple triggers on same object is never a good approach. So I will suggest you to merge all triggers and have only one trigger and have a single test class to test the functionality. 

 

Problem #2 : It looks like your code which is getting executed by your trigger is not bulkified properly. You need to check if there is any SOQL which is getting executed in a loop.

 

For more information please refer my blog on how to write a trigger cleanly. Do let me know if you need any further help.

 

Thanks

Chandra

Blog Site :http://cmlohani-force.blogspot.com

All Answers

cmlcml

Problem #1 :  Having multiple triggers on same object is never a good approach. So I will suggest you to merge all triggers and have only one trigger and have a single test class to test the functionality. 

 

Problem #2 : It looks like your code which is getting executed by your trigger is not bulkified properly. You need to check if there is any SOQL which is getting executed in a loop.

 

For more information please refer my blog on how to write a trigger cleanly. Do let me know if you need any further help.

 

Thanks

Chandra

Blog Site :http://cmlohani-force.blogspot.com

This was selected as the best answer
FlorentFlorent

Thanks a lot for your reply, Chandra.

 

I was fearing such answers, in fact!

 

Having mutiple triggers felt like the wrong approach, so now I guess I'll have to integrate other ppl's work in mine '-(

 

As for the SOQL in loop, well, it happens my trigger calls SOQL requests but outside of FOR loops (i had understood that :-). What happens is, one of the other guys test classes does a loop creating opportunities. And indeed, I have not bulkyfied trigger calls. I'l try and see if I understand how to do this by myself, but if not, I shall turn to your help with no hesitation!

 

Again thanks a lot for such helpful reply.