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
Ramon PereiraRamon Pereira 

Help with Triggrer

 

Hello,

 

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';

     leadstoupdate.add(newlead);

}

 

if (leadstoupdate.size() > 0){

  update leadstoupdate;

}