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
Arun KArun K 

Problem in Recursive trigger

below is my trigger where I am trying to update the value in field But couldnt update because of recursive trigger.

 

what needs to be done to update the value

 

trigger UpdateCallsByOtherTerritories on String__c(after update) {
for( String__c doc:trigger.new){            

    List<Account> AccountList = [Select Total_Calls_Formula__c,called_by_other__c , OwnerId, Co_Owner__c, Name from Account where name = :doc.Account__r.name];
    List<Account> listOfUpdatedAccounts = new List<Account>();
    
    for (account indexAccount:AccountList)
    {
        if (indexAccount.OwnerId == userinfo.getuserid()) { }
        else
        {
            indexAccount.called_by_other__c = indexAccount.called_by_other__c + (doc.Updated_CallString__c - Trigger.oldMap.get(doc.Id).Updated_CallString__c);
            
        }}

 

deepabalisfdcdeepabalisfdc

You are trying to update Account object indexAccount I gues. IS there other triggers on Account which is getting called?
Or need to know purpose and problem exactly. It will help others to answer if you supply that.

AKS018AKS018
Better to use Before update event in trigger
Arun KArun K

I need to execute this trigger after update.

deepabalisfdcdeepabalisfdc

I hope then that your trigger code is best for requirement. Try this:

trigger UpdateCallsByOtherTerritories on String__c(after update) {
	if(FutureTriggerController.controlUpdate == false){
		for( String__c doc:trigger.new){            
			
				List<Account> AccountList = [Select Total_Calls_Formula__c,called_by_other__c , OwnerId, Co_Owner__c, Name from Account where name = :doc.Account__r.name];
				List<Account> listOfUpdatedAccounts = new List<Account>();
				List<Account> toUpdateAccList = new List<Account>();
				for (account indexAccount:AccountList)
				{
					if (indexAccount.OwnerId == userinfo.getuserid()) {
						//do something
					}
					else
					{
						indexAccount.called_by_other__c = indexAccount.called_by_other__c + (doc.Updated_CallString__c - Trigger.oldMap.get(doc.Id).Updated_CallString__c);
						toUpdateAccList.add(indexAccount);
					}
			   
			   }
			
			FutureTriggerController.controlUpdate == true;
			update toUpdateAccList;
		   
		}
	}
}

 and class used in this trigger to control recursive call:

public class FutureTriggerController{

    public static boolean controlUpdate = false;

 
}

 Let me know if it helps

Arun KArun K

Thanks for that.

 

May be I am close to achieve the updation.

 

So basically My req is I have string object where I have to update and I should replicate the changes in Account called by other field.

 

That updation is not happening