+ Start a Discussion
Bhuvanakruthi MudholeBhuvanakruthi Mudhole 

Create a field on 'isRecovered' of type Checkbox on account.If account is undeleted from recycle bin then make this field 'true' (Hint:After Undelete Trigger On Account)

Best Answer chosen by Bhuvanakruthi Mudhole
Ravi Dutt SharmaRavi Dutt Sharma
Hope this helps.
 
trigger AccountTrigger on Account(after undelete){
	
	List<Account> recoveredAccounts = new List<Account>();
	if(Trigger.isAfter && Trigger.isUndelete){
		for(Account acc: Trigger.new){
			acc.isRecovered__c = true;
			recoveredAccounts.add(acc);
		}
		
		if(recoveredAccounts.size() > 0){
			Database.update(recoveredAccounts,false);
		}
	}
}

 

All Answers

Ravi Dutt SharmaRavi Dutt Sharma
Hope this helps.
 
trigger AccountTrigger on Account(after undelete){
	
	List<Account> recoveredAccounts = new List<Account>();
	if(Trigger.isAfter && Trigger.isUndelete){
		for(Account acc: Trigger.new){
			acc.isRecovered__c = true;
			recoveredAccounts.add(acc);
		}
		
		if(recoveredAccounts.size() > 0){
			Database.update(recoveredAccounts,false);
		}
	}
}

 
This was selected as the best answer
Bhuvanakruthi MudholeBhuvanakruthi Mudhole
 if(recoveredAccounts.size() > 0){
    Database.update(recoveredAccounts,false);

Why did we use these statements?
Akshay_DhimanAkshay_Dhiman
Hi Bhuvanakruthi,

Try this code
//Helper Class
public class FatchAccountFromRecycleBin {
    public static void getMethodAccount(List<Account> acctList){
        List<Account> acct=new List<Account>();
        set<Id> sid = new Set<Id>();
        for(Account ac:acctList){
            sid.add(ac.Id);
            
        }
        system.debug('SET ID:'+sid);
        List<Account> acctAccount = [select id,isRecovered__c,name from Account where Id=:sid];
        for(Account ac : acctAccount)
        {
            ac.isRecovered__c = true;
            acct.add(ac);
        }
     
         update acct;
  }

}
//Trigger
trigger AccounntNumberOfEmployee on Account (after undelete){
   
    if(Trigger.isUndelete && Trigger.isAfter){
         FatchAccountFromRecycleBin.getMethodAccount(Trigger.new);
    }
    
}


Thanks 
Akhsay