+ Start a Discussion
Ramon PereiraRamon Pereira 

Help with Triggrer




I have the following problem: I need to capture the number of minutes that the User was not a case to answer. I used the following logic in triggrer below:


if(  (casesSLA[0].Tempo_Atendimento__c == 0)&&(casesSLA[0].Disposicao_imediata__c != null)){  
                                casesSLA[0].Tempo_Atendimento__c = Math.floor((casesSLA[0].LastModifiedDate.getTime () 
                                                        - casesSLA[0].CreatedDate.getTime ())* 0.00001666666666666667 );




But she is a triggrer before update, then the User have to save twice the record so that it can capture time. When reading the documentation, I found that with triggre after update is not possible to perform DML operations.

Anybody know any other way so that I can perform this calculation without forcing the User to save twice the record?

thank you

Jeff MayJeff May

In an after trigger, you just create a new record using the ID of the record you want to update.


for example, in an after trigger.


List<Lead> leadstoupdate = new List<Lead>();


for (Lead L : trigger.new){


     Lead newlead = new Lead();

     newlead.Id = L.Id;

     newlead.OtherField__c = 'Hi';




if (leadstoupdate.size() > 0){

  update leadstoupdate;