Issue here. whenever we update the same object in trigger then always use before update/before insert.
If you want to update other object records (not trigger object) then use after context.
In your case. You are updating same object in after context. So it is firing the trigger again and again. And finally it stuck in a loop that's why you are getting
Maximum Trigger Depth Exceeded error.
Just use before update context and try to update field. This way you don't have to perform DML because you are modifying the data before committing to database.
Check: Triggers and Order of Execution
trigger updateAoC on Contract_vod__c(before update) {
String Uid = UserInfo.getUserId();
for (Contract_vod__c c : trigger.new) {
if(c.AoC_Status_abv__c=='Completed_Electronic'){
s.Completed_By_abv__c=Id.valueof(Uid);
}
}
}
Updates
Trigger
trigger updateAoC on Contract_vod__c(after update) {
updateContract handler = new updateContract();
if(Trigger.isUpdate && Trigger.isAfter && updateContract.isUpdate)
{
updateContract.isUpdate = false;
handler.onAfterUpdate(Trigger.new);
}
}
Handler
public class updateContract{
public static Boolean isUpdate = true;
public void onAfterUpdate(List<Contract_vod__c> lstContract_vod)
{
List<Contract_vod__c> contracts= new List<Contract_vod__c>();
String Uid = UserInfo.getUserId();
for (Contract_vod__c c : trigger.new) {
Contract_vod__c s= new Contract_vod__c(Id=c.Id);
if(c.AoC_Status_abv__c=='Completed_Electronic')
s.Completed_By_abv__c=Id.valueof(Uid);
contracts.add(s);
}
update contracts;
updateContract.isUpdate = true;
}
}