+ Start a Discussion
muni kmuni k 

steps to apex program for restore the deleted records in salesforce...

steps to apex program for restore the deleted records in salesforce...For example custom object name is Account, Its have some records.
Now i want to store deleted records to another location like Deleted Accounts Tab..
What are the steps i need to follow for solve this...Pls let me know

Thanks for advance...
Hi Vasumuni,

Try with beloe code it will work .

List<DeletedAccount> delAccountList=new List<DeletedAccount>();
For(Account acc :[SELECT id,Name FROM Account WHERE isDeleted=True ALL ROWS ]){
  DeletedAccount  delAc=new DeletedAccount();
  insert delAccountList;
}catch(DmlException de ){
Let me know if it helps .

muni kmuni k
Hi Manoj,
Thank u for response..

Actually i am new to salesforce. My code is like this..Please help me where i could place this code...I created new custom object is DeletedAccount for restore the deleted records..

The main task is what ever records are deleted it should be store in DeletedAccount object..

Please help me..


<apex:page standardController="Account">

    <apex:form >

        <apex:pageBlock title="Edit Account for {!$User.FirstName}">

            <apex:pageMessages />

            <apex:pageBlockButtons >

                <apex:commandButton value="Save" action="{!save}"/>


            <apex:pageBlockSection >

                <apex:inputField value="{!account.name}"/>
                  <apex:inputField value="{!account.accountnumber}"/>
                   <apex:inputField value="{!account.annualrevenue}"/>
                    <apex:inputField value="{!account.industry}"/>
                    <apex:inputField value="{!account.accountsource}"/>
                     <apex:inputField value="{!account.numberofemployees}"/>
                      <apex:inputField value="{!account.naicscode}"/>
                     <apex:inputField value="{!account.phone}"/>
                     <apex:inputField value="{!account.fax}"/>
                      <apex:inputField value="{!account.website}"/>






public with sharing class custable {

     public string recid{get;set;}

   public string row{ get; set;}
   public list<Account> Acclst{get;set;}
   Public Account A;

   public List<Contact> contacts {get; set;}

   public custable(){

   Acclst = [select Id,Name from Account ];

   public pagereference deleteAccount()
   account ac=[select id,name from account where id=:recid];
   delete ac;

   pagereference ref =new pagereference('/apex/custable');
   return ref;


  public void setupContacts()
     contacts=[select id, FirstName, LastName from Contact where AccountId=:recId];

<apex:page controller="custable" sidebar="false">
    <apex:form >
        <apex:pageBlock title="AccountTable">
            <apex:pageBlockTable value="{!Acclst}" var="A">
            <apex:column headerValue="EDIT">
            <apex:outputLink value="/{!A.id}/e" id="edit">Edit</apex:outputLink>
            <apex:column headerValue="DELETE">
            <apex:commandLink action="{!deleteAccount}" onclick="if(!confirm('Are you sure?')) return false;">Del
            <apex:param value="{!A.Id}" name="idToDel" assignTo="{!recid}"/>
            <apex:column headerValue="NAME OF THE ACCOUNT" > 
            <apex:commandLink value="{!A.Name}" action="{!setupContacts}"  rerender="CONT">
              <apex:param value="{!A.Id}" name="idForConts" assignTo="{!recid}"/>
            <apex:column value="{!A.Id}"/>
    <apex:pageBlock title="Contacts" id="CONT">
      <apex:pageBlockTable value="{!contacts}" var="contact" >
        <apex:column value="{!contact.FirstName}"/>
        <apex:column value="{!contact.LastName}"/>

Can you tell bit more about you rrequirment .

Amit  TrivediAmit Trivedi
Hi Vasumun,

Write batch  apex or scheduler and run it on daily basis or write trigger(after delete) ,In which fetch all acounts in list which are deleted by putting  IsDeleted = true in where clause of soql query and then insert it.

Amit Trivedi
muni kmuni k
Hi Manoj,
The main requirement is deleted  records are to store another new custom object..

Thank u for u r patiency..
HI Vasumuni,

My question here is you need to create the custom object  DeletedAccount__c record while deleting from your page or if you will create once in a day ,suppose in morning or evening .How many record you have created today will create record in your custom object .