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
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...
ManojjenaManojjena
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();
    delAc.Name__c=acc.Name;
    delAccountList.add(delAc);
}
Try{
  insert delAccountList;
}catch(DmlException de ){
   System.debug(de);
}
Let me know if it helps .

Thanks 
Manoj
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..

Custom_Account.vfp:

<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:pageBlockButtons>

            <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}"/>

            </apex:pageBlockSection>

        </apex:pageBlock>

    </apex:form>

</apex:page>

custable.apxc:

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');
   ref.setredirect(true);
   return ref;

  }

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


customVFpage.vfp:
<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>
            <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:commandLink>
            </apex:column>
            <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:commandLink>
            </apex:column>  
            <apex:column value="{!A.Id}"/>
            </apex:pageBlockTable>
        </apex:pageBlock>
  
    <apex:pageBlock title="Contacts" id="CONT">
      <apex:pageBlockTable value="{!contacts}" var="contact" >
       
        <apex:column value="{!contact.FirstName}"/>
        <apex:column value="{!contact.LastName}"/>

          
      </apex:pageBlockTable>
    </apex:pageBlock>
    </apex:form>
</apex:page>
 
ManojjenaManojjena
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.

Thanks,
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..
ManojjenaManojjena
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 .

Thanks 
Manoj