0

I know you can retrieve all fields from a single Object in Salesforce. I have started doing something like this:

SObjectType accountType = Schema.getGlobalDescribe().get('Account');
Map<String,Schema.SObjectField> mfields = 
accountType.getDescribe().fields.getMap();

What do I need to use to query and retrieve on all object types of all deleted records in the recycle bin?

I need to schedule a job that regularly does this in order to backup deleted records every week.

1

You will need to do a separate query for each SObject type with IsDeleted = true in the where clause: there is no "query by any type" mechanism.

There are potentially two levels of iteration:

  • Over each SObjectType (that you could get from the describe call you list or through some configuration that you set because there are probably many types that are not relevant to your business)
  • Your work will be subject to governor limits so if large numbers of records are involved you will need to break the work up into sets of records

You can probably use Batch Apex for both.

|improve this answer|||||
  • That is what I thought, that is the main problem --- by doing that I will undoubtably hit the api call limits! – TheAdmin Jan 31 '18 at 14:13
0

Retrieve the data in Recycle Bin

Create a Apex Class

public class allrows {
    public list<account> acc{set;get;}
    public allrows(){
        acc=new list<account>([select id,name from account where isDeleted = true all rows]);
    }
}

VF Page

<apex:page controller="allrows">
    <apex:pageBlock >
    <apex:pageBlockSection >
        <apex:pageBlockTable value="{!acc}" var="c"> 
        <apex:column value="{!c.name}"/>
        <apex:column value="{!c.id}"/>
        </apex:pageBlockTable>
        </apex:pageBlockSection>
    </apex:pageBlock>
</apex:page>

Or

Find all Deleted records - SELECT Id,Name FROM Account WHERE IsDeleted = true Find records with specific names - SELECT Id,IsDeleted,LastName FROM Account WHERE LastName = 'Account A'

Or

https://help.salesforce.com/articleView?id=How-to-retrieve-my-records-and-data-that-has-been-lost-or-deleted-1327108681812&language=en_US&type=1

|improve this answer|||||
  • This is specific to one object type (in your example 'Account') I need to query on all object types that have been deleted! (IsDeleted= true) – TheAdmin Jan 31 '18 at 14:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.