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
Tashika GuptaTashika Gupta 

how to check the record is undeleted from recycle bin

i have a custom checkbox feild called recovered on account.Whenver the record is recovered from recycle bin i want that the recovered feild should be checked.

I want to implement this through trigger. how can i do this ???
 
Best Answer chosen by Tashika Gupta
PratikPratik (Salesforce Developers) 
Hi Tashika,

When you undelete the records, they will be like all other normal records and no way to identify if it's undeleted.

Trigger:


trigger undlttrgracc on account(after undelete) {
list<account> undeltedacc=new list<account>();
   for (account ld: trigger.new) {
    account acc = new account();
    acc.id=ld.id;
    acc.Recoverd__c=true; //recovered is checkbox
    undeltedacc.add(acc);
 }
    update undeltedacc;
}


However you can check the Undelete() api call.
https://www.salesforce.com/developer/docs/api/Content/sforce_api_calls_undelete.htm



Thanks,
Pratik
 

All Answers

PratikPratik (Salesforce Developers) 
Hi Tashika,

When you undelete the records, they will be like all other normal records and no way to identify if it's undeleted.

Trigger:


trigger undlttrgracc on account(after undelete) {
list<account> undeltedacc=new list<account>();
   for (account ld: trigger.new) {
    account acc = new account();
    acc.id=ld.id;
    acc.Recoverd__c=true; //recovered is checkbox
    undeltedacc.add(acc);
 }
    update undeltedacc;
}


However you can check the Undelete() api call.
https://www.salesforce.com/developer/docs/api/Content/sforce_api_calls_undelete.htm



Thanks,
Pratik
 
This was selected as the best answer
Axaykumar VaruAxaykumar Varu
Hi-

Create after undelete trigger, use below sample code to update the field you want:
trigger OnUndeleteAccount on Account (after undelete) {
	
    List<Account> lstAcc = new List<Account>();
    for(Account acc : trigger.new){
        Account ac = new Account(Id = acc.Id);
        ac.description = 'Recoverd from Recycle bin';
        lstAcc.add(ac);
    }
    
    update lstAcc;
}

Regards,
Axaykumar
Tashika GuptaTashika Gupta
hey, It worked thanks.. Thanks and Regards, Tashika Gupta __________________________________________________________ Zensar Technologies Ltd Zensar Knowledge Park, Plot#4, MIDC, Kharadi, Off Nagar Road, Pune – 411014 Mobile : +91- 7030200053 | Email : tashika.gupta@zensar.in
Axaykumar VaruAxaykumar Varu
Glad to hear that you got the solution, please mark the post as solved. so that it can help others.

Thanks,
Axaykumar