+ Start a Discussion
Sahasra NSahasra N 

How can the helper class warn users when the trigger exceeds DML governor limits?

Please help me with the correct answer.

A developer creates an Apex helper class to handle complex trigger logic. How can the helper class warn users when the trigger exceeds DML governor limits?
A. By using ApexMessage.Message() to display an error message after the number of DML statements is exceeded.
B. By using Messaging.SendEmail() to conthtinue the transaction and send an alert to the user after the number DML statements is exceeded.
C. By using PageReference.setRedirect() to redirect the user to a custom Visualforce page before the number DML statements is exceeded.
D. By using Limits.getDMLRows() and then displaying an error message before the number of DML statements exceeded.
deepak balur 19deepak balur 19
The Answer is A. This will throw your error on the UI and then some fix will have to be done so that governors limit is not hit.
You can alsp check in your code if you are getting to hit the gov limits and try and defer certain processing async if possible.
Mudasir WaniMudasir Wani
We can use Limits.getDMLRows() and then displaying an error message before the number of DML statements exceeded.
http://developer.salesforce.com/page/Best_Practice:_Use_of_the_Limits_Apex_Methods_to_avoid_Hitting_Governor_Limits  (http://developer.salesforce.com/page/Best_Practice:_Use_of_the_Limits_Apex_Methods_to_avoid_Hitting_Governor_Limits )
Michele MilidoniMichele Milidoni
does 
ApexMessage.Message()

exist? I cannot find it. I guess right answer is D.
B is incorrect because the transaction will not continue if trigger exceeds governor limits, and all DMLs will be rolled back.
Naresh Vaddepallli GNaresh Vaddepallli G
D is the right answer. The question suggest to warn User. Also there is no ApexMessage class. It has to be ApexPages. 
Sudhir gonuguntlaSudhir gonuguntla
it is not required to handle it separetly. if the transation hit governot limits. it will display the error to user on page. 

one more way to handle : 
 
ERRORS = new List<String>();
if(Limits.getDmlRows() >10000 || Limits.getDmlStatements() >150)
ERRORS.add();



 
Rahul Garg SFDRahul Garg SFD
Warning should be shown BEFORE the trigger exceeds governor limits. So the Answer should be D.